How do I write a small number to the console without the e notation in C#?

Viewed 244

When I try to display a very small or a very big number, it shows us the number with the e notation.
How do I bypass this issue?

Things I have tried:

Console.WriteLine(Double.Parse("1E-10", System.Globalization.NumberStyles.Float));
/* System.FormatException: Input string was not in a correct format.
 *     at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
 *     at Rextester.Program.Main(String[] args)
 */
Console.WriteLine(Convert.ToString(Math.Pow(10,-10)));
// returns 1E-10
double num = Math.Pow(10,-10);
Console.WriteLine(num.ToString());
// returns 1E-10
1 Answers

For this one you need to use a string format. For your case Pow(10, -10) will return 0.0000000001, so you will need to use a format that can display 10 decimal places.

You may declare a string format like this:

const string format = "0.##########";

Then use: Console.WriteLine(num.ToString(format));

Related