Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. 1.2 00000001.20
  2. .2 00000000.20
  3. -.2 -0000000.20
  4. 12 00000012.00
  5. 0 00000000.00
  6. -0 00000000.00
  7. 12.555 00000012.55
  8.  
  9. {0:00000000.00;0:0000000.00;0:00000000.00}
  10.  
  11. string format = "{0:00000000.00;-0000000.00}";
  12.  
  13. Console.WriteLine(string.Format(format, 1.2));
  14. Console.WriteLine(string.Format(format, .2));
  15. Console.WriteLine(string.Format(format, -.2));
  16. Console.WriteLine(string.Format(format, 12.0));
  17. Console.WriteLine(string.Format(format, -0.0));
  18. Console.WriteLine(string.Format(format, 12.555));
  19.  
  20. {position:postive format;negative format;zero format}
  21.  
  22. string.Format("{0:00000000.00}", 1.2)
  23.  
  24. double d = -12.365;
  25. string s = d.ToString("0:00000000.00");//-0:00000012.37
  26. string sOut = d.ToString("00000000.00")//-00000012.37
  27.  
  28. using System;
  29. using System.Linq;
  30. using System.Text;
  31.  
  32. namespace ConsoleApplication3
  33. {
  34. class Program
  35. {
  36. static void Main(string[] args)
  37. {
  38. Func<double, string> toFixedWidth = (d) => {
  39. return string.Format("{0:00000000.00;-0000000.00}", d);
  40. };
  41.  
  42. foreach (var d in new double[] { 1.2, 0.2, -0.2, 12, 0, -0, 12.555 })
  43. {
  44. Console.WriteLine(toFixedWidth(d));
  45. }
  46. }
  47. }
  48. }
  49.  
  50. 00000001,20
  51. 00000000,20
  52. -0000000,20
  53. 00000012,00
  54. 00000000,00
  55. 00000000,00
  56. 00000012,56
  57. Press any key to continue . . .
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement