what exactly precision of 15 digits mean for float

2019-08-20 16:32发布

问题:

As per the http://msdn.microsoft.com/en-us/library/ms173773.aspx

float is approx. data type.

But also in the same article it is being mentioned that float has precision of 15 digits.

What exactly it mean by Precision of 15 digits ?

回答1:

It means that the first 15 digits are approximately correct. Thanks to IEEE 754 there are many numbers that can't be exactly represented, but you can be sure that the first 15 digits are very close.



回答2:

Your numbers are exact with a precision of 15 digits. That means if you calculate something and store the outcome as a float, you can be sure the first 15 digits are the right result. After that they might (and usually are) not.