-3

I have a double that shows scientific notations like this: 2.95E-05 I get those values from a JSON string as double directly. I wonder how the double can be converted so it instead shows all zeros like a normal number? (0.0000295)

Below attempt does not work and still shows: 2.95E-05

Thank you!

 double value = 2.95E-05;
 value = double.Parse(value.ToString(), System.Globalization.NumberStyles.Any);
 MessageBox.Show(value.ToString());
Andreas
  • 1,121
  • 4
  • 17
  • 34

1 Answers1

0

There are several ways to do this and it depends on whether you want fixed precision or padded with 0's.

double value = 2.95E-05;
value = double.Parse(value.ToString(), System.Globalization.NumberStyles.Any);
Console.WriteLine(string.Format("{0:F10}",value));
Console.WriteLine($"{value:F10}");
Console.WriteLine(value.ToString("F10}"));
Console.WriteLine($"{value:0.##########}");

Please take a look at the following to ascertain how to format numeric values, it's all you need to know and more. Although there is a lot of information here, the easiest way is too look at the examples:

halfer
  • 19,824
  • 17
  • 99
  • 186
TheGeneral
  • 79,002
  • 9
  • 103
  • 141