Why is the Convert.ToDouble (string) round?

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

What is the maximum number of significant digits? Could not find it in the documents.

+3
source share
4 answers

From MSDN :

Accuracy: 15-16 digits.

+3
source

Of course, there is maximum accuracy. This is the maximum that you can express with the bits used to store the double. For this line, you can try Decimal instead.

+7
source

, . IEEE 754-1985 .

,

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

, , .

+2

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

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

+1
source

Source: https://habr.com/ru/post/1698588/


All Articles