In C#, if a double number has more than 5 zero (ex: 0.0000456), it will display as 4.56E-05. But I want to display as 0.0000456. Is there anyway to change the display format? Please help!
Asked
Active
Viewed 54 times
-2
-
Have you looked through the numeric format strings page on MSDN? – BradleyDotNET Jan 05 '18 at 19:48
-
See [Standard Numeric Format Strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings). – NightOwl888 Jan 05 '18 at 19:52
1 Answers
0
Use formatting to accomplish this.
double test = 0.0000456;
Console.WriteLine(test);
Console.WriteLine("{0:F7}", test);
Console.ReadKey();
Output
4.56E-05
0.0000456
Max
double test =
0.00000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000001;
Console.WriteLine(test);
Console.WriteLine("{0:F99}", test);
Console.ReadKey();
Output
1E-99
0.00000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000001;

ReRoute
- 371
- 1
- 13