views:

987

answers:

4

For example, Convert.ToDouble("0.1234567890123456789") = 0.123456789012346

What is the maximum number of significant figures? Couldn't find it in the docs.

+3  A: 

From MSDN:

Precision: 15-16 digits.

Chris Marasti-Georg
+7  A: 

Of course there's a maximum precision. It's the maximum that you can express with the bits used to store the double. For that string you might try Decimal instead.

Joel Coehoorn
+2  A: 

If you really want to understand binary representation of floating point numbers, see IEEE 754-1985 on Wikipedia.

Basically, it's

sign * 1.mantissa * 2^(exponent - bias)

The number of bits allocated to the mantissa and exponent fields determines the precision of the number.

Kip
+1  A: 

http://en.wikipedia.org/wiki/Double_precision

A double only has 64 bits of storage, and some of them are used for the sign and exponent, so there are a limited number of digits (usually 15) for the fractional part. A float has only 32 bits, so 8-9 digits of precision. Also some numbers cannot be represented exactly using a floating point number so you may see some rounding errors in your conversions.

sk
According to MSDN, a .NET float gets 7 digits of precision.
Chris Marasti-Georg
A `double` has 53 bits (15.95 digits) of precision, while a `float` has 24 bits (7.22 digits).
dan04