Tuesday, 15 February 2011

c# - Format doubles with General numeric format and pad right with zeros -


I am trying to output doubles in different sizes, negative and non-negative columns. I would like to use the G5 standard numerical format so that if it is appropriate it is the exponential form (i.e. the price is very small), but otherwise the regular formatting but I want the values ​​to be aligned with zero so that the line in the column (such as pad Zero normally, and the pin zero before the exposures of x). Currently, I have it now:

  string.Format ("{0} {1} {2}", a.ToString ("G5"), B. Teststring ("G5" ), C.ToString ("G5");  

It does not work much because it does not pad. I would like to see my output like this:

  1.234000000 0.123400000 1.23450 E-03 4.56780 E-088 -1.2345 E-09 0.001234000 // Negative indications can line with everything -12.34500000 0.045678900  

How can I get it?

Edit: Use the code: {0:10} with the numbers given above:

  1.234 0.1234 0.0012345 4.5678 e-088 -1.2345 E-099 0.001234 - 12.345 0.045679 -1.2345 E-066  


No comments:

Post a Comment