How to convert double to string without permission up to 10 (E-05)
double value = 0.000099999999833333343; string text = value.ToString(); Console.WriteLine(text);
I want the text of the line to be 0.000099999999833333343 (or almost that, I'm not doing rocket :)
I tried the following options
Console.WriteLine(value.ToString()); // 9,99999998333333E-05 Console.WriteLine(value.ToString("R20")); // 9,9999999833333343E-05 Console.WriteLine(value.ToString("N20")); // 0,00009999999983333330 Console.WriteLine(String.Format("{0:F20}", value)); // 0,00009999999983333330
Doing a tostring N20 or F20 format seems the closest to what I want, but in the end I have a lot of trailing zeros, is there a tricky way to avoid this? I would like as close as possible to the double representation of 0.000099999999833333343
tostring c #
Makach Aug 23 '09 at 18:21 2009-08-23 18:21
source share