Kalai Kalai - 4 years ago 186
C# Question

How to convert the double value to string without losing the data in c#

I have a double value as below

propertyValue = 1994.7755474452554,

When i convert this double value to string, it shows the result as

value = propertyValue.ToString(),

value will be as, "1994.77554744526"

It has round off the last digit, 2554 to 26

But i do not want to round off the doubt value. Share your ideas.

Answer Source

By default the .ToString() method of Double returns 15 digits of precision. If you want the full 17 digits that the double value holds internally, you need to pass the "G17" format specifier to the method.

String s = value.ToString("G17");

This will prevent the rounding off of double value when converted to string.

value = propertyValue.ToString("G17");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download