C# double.ToString() max number of digits and trailing zeros

It is okay to use value.ToString("0.######"). However, you should consider another thing: double is not a decimal (base 10) number. You should not rely on the decimal representation of the number to be anything reasonable - plenty of normal decimal base 10 numbers require infinite decimal expansion in base 2.

If you do care about the decimal representation, it might be a better idea to use decimal instead - it's also a floating point number, but in base 10.

And in either case, this involves rounding - that might or might not be what you want.

Tags:

C#

String

Format