echo number_format(19.99 * 100, 20); // output:1,998.99999999999977262632
Why is this so? How floating-point types are stored. My idea might be that floating-point types are inherently not exactly stored.
Solve this problem and know why intval
the value is 1998
.
Reply content:
echo number_format(19.99 * 100, 20); // output:1,998.99999999999977262632
Why is this so? How floating-point types are stored. My idea might be that floating-point types are inherently not exactly stored.
Solve this problem and know why intval
the value is 1998
.
The storage accuracy of floating-point numbers is related to the system, and PHP typically uses the IEEE 754 double-precision format, which defaults to 20-bit effective precision. Floating point numbers
Floating Point Usage Guide
Floating-point type http://php.net/manual/zh/language.types.float.php with Chinese characters