fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. // General: g o G
  8. Console.WriteLine(1.2345.ToString("G"));
  9. Console.WriteLine(0.0001.ToString("g"));
  10. Console.WriteLine(1.2345.ToString("G3"));
  11. Console.WriteLine(12345.ToString("G3"));
  12.  
  13. // Punto fijo: F
  14. Console.WriteLine(2345.678.ToString("F2"));
  15. Console.WriteLine(2345.6.ToString("F2"));
  16.  
  17. // Puno fijo con separador de gruipo (numérico):
  18. Console.WriteLine(2345.678.ToString("N2"));
  19. Console.WriteLine(2345.6.ToString("N2"));
  20.  
  21. // Pad con ceros a la izquierda: D
  22. Console.WriteLine(123.ToString("D5"));
  23. Console.WriteLine(123.ToString("D1"));
  24.  
  25. // Notación exponencial: E o e
  26. Console.WriteLine(56789.ToString("E"));
  27. Console.WriteLine(56789.ToString("e"));
  28. Console.WriteLine(56789.ToString("E2"));
  29.  
  30. // Moneda: C
  31. Console.WriteLine(1.2.ToString("C"));
  32. Console.WriteLine(1.2.ToString("C4"));
  33.  
  34. // Porcentaje: P
  35. Console.WriteLine(.503.ToString("P"));
  36. Console.WriteLine(.503.ToString("P0"));
  37.  
  38. // Hexadecimal: X o x
  39. Console.WriteLine(47.ToString("X"));
  40. Console.WriteLine(47.ToString("x"));
  41. Console.WriteLine(47.ToString("X4"));
  42.  
  43. // Round-trip: R
  44. Console.WriteLine((1f / 3f).ToString("R"));
  45. }
  46. }
Success #stdin #stdout 0.04s 23920KB
stdin
Standard input is empty
stdout
1.2345
0.0001
1.23
1.23E+04
2345.68
2345.60
2,345.68
2,345.60
00123
123
5.678900E+004
5.678900e+004
5.68E+004
$1.20
$1.2000
50.30 %
50 %
2F
2f
002F
0.333333343