Let’s say we have the following simple code
string number = "93389.429999999993";
double numberAsDouble = Convert.ToDouble(number);
Console.WriteLine(numberAsDouble);
after that conversion numberAsDouble variable has the value 93389.43. What can i do to make this variable keep the full number as is without rounding it? I have found that Convert.ToDecimal does not behave the same way but i need to have the value as double.
——————-small update———————
putting a breakpoint in line 2 of the above code shows that the numberAsDouble variable has the rounded value 93389.43 before displayed in the console.
93389.429999999993cannot be represented exactly as a 64-bit floating point number. Adoublecan only hold 15 or 16 digits, while you have 17 digits. If you need that level of precision use adecimalinstead.(I know you say you need it as a double, but if you could explain why, there may be alternate solutions)