I am storing a value (represented as a string originally) like this – 12345678901234.12345678912 – in a double variable. After storing, it is represented in an exponential format (with an e). How do i convert this exponential representation to the original(string) representation?
Dim s as string = "1234567891234567.123456789"
Dim d as Double
Double.TryParse(s, d)
Console.WriteLine(d) 'Prints 1.23456789123457E+15
Using Decimal solves the problem but why cant Double do it?
Your string contains 25 significant digits.
doublesimply doesn’t retain that amount of information. Evendecimalcan barely hold that much (28/29 digits). From the docs forSystem.Double:You should read my articles on binary floating point and decimal floating point for more information – they come at the topic from a C# point of view, but you’re obviously using the same types from VB.
In your particular case, the exact
doublevalue closest to 1234567891234567.123456789 is just 1234567891234567 – you’re losing all the information after the decimal point.