Reputation: 172
I am trying to convert a number in exponential form to its decimal equivalent. For example:
3e43 => 3 000 000 000 000 000 000 000 000 000 000 000 000 000 000 0
I've read the docs and it says that I may do this with
double.Parse(expNumber.ToString(), NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);
But when I try to convert 3e43 to decimal it just converts it to 3E+43 and not to the number I am expecting (I know it's about the double datatype precision). Is there a way to do that?
Also, is there any way to convert 3e-43 to its decimal equivalent? It seems that decimal.toString doesn't work this time as it is such an small number.
Upvotes: 0
Views: 305
Reputation: 81473
If you want to see all the zeros
just use Double.ToString
it has various overloads to do different things
var input = "3e43";
var val = double.Parse(input, NumberStyles.AllowExponent | NumberStyles.AllowDecimalPoint);
Console.WriteLine(val);
Console.WriteLine(val.ToString("N0"));
Console.WriteLine(val.ToString("f"));
Output
3E+43
30,000,000,000,000,000,000,000,000,000,000,000,000,000,000
30000000000000000000000000000000000000000000.00
Additional resouces
Standard Numeric Format Strings
Upvotes: 1