Wednesday, 21 August 2013

Why does Convert.ToString format doubles in this way?

Why does Convert.ToString format doubles in this way?

Consider the following code:
var rateUsed = 0.00000001;
var rateUsedConvertToString = Convert.ToString(rateUsed);
var rateUsedToString = rateUsed.ToString();
Instead of my strings being "0.00000001", they are both "1E-08". I don't
have control over the initial type of rateUsed, it is a double, and I want
the exact string representation of the double.
Why does this happen, and how would I get 0.00000001 as a string, if this
started off as a double value?

No comments:

Post a Comment