Php
The problem is found when using the PHP round function for fractional control, as follows:
Round (9999999999999.99, 2) expected value: 9999999999999.99; actual: 10000000000000
Round (1111111111111.11, 2) expected value: 1111111111111.11; actual: 1111111111111.1
Are there any similar problems? Is this a known bug in PHP? Did not see the official release of the relevant instructions.
Note: The PHP version on my machine is 5.3.6
Reply to discussion (solution)
Round function No problem
$a = 1111111111111.11;echo $a;
Refer to PHP for a description of floating-point type accuracy.
http://www.php.net/manual/zh/language.types.float.php
Round function No problem
$a = 1111111111111.11;echo $a;
Refer to PHP for a description of floating-point type accuracy.
http://www.php.net/manual/zh/language.types.float.php
$a = 1111111111111.11;
echo $a;
What does this code show? Did not call round?
Round function No problem
$a = 1111111111111.11;echo $a;
Refer to PHP for a description of floating-point type accuracy.
http://www.php.net/manual/zh/language.types.float.php
$a = 1111111111111.11;
echo $a;
What does this code show? Did not call round?
The output is 1111111111111.1, which means 1111111111111.11 is converted to 1111111111111.1 during script compilation.
It is possible that the floating-point type of PHP cannot store 1111111111111.11 for precision reasons.
Didn't you read the official PHP instructions? "So never believe that the floating-point results are accurate to the last one."
Round function No problem
$a = 1111111111111.11;echo $a;
Refer to PHP for a description of floating-point type accuracy.
http://www.php.net/manual/zh/language.types.float.php
$a = 1111111111111.11;
echo $a;
What does this code show? Did not call round?
The output is 1111111111111.1, which means 1111111111111.11 is converted to 1111111111111.1 during script compilation.
It is possible that the floating-point type of PHP cannot store 1111111111111.11 for precision reasons.
Didn't you read the official PHP instructions? "So never believe that the floating-point results are accurate to the last one."
What should I do with the numbers I'm trying to show in full?
Round function No problem
$a = 1111111111111.11;echo $a;
Refer to PHP for a description of floating-point type accuracy.
http://www.php.net/manual/zh/language.types.float.php
$a = 1111111111111.11;
echo $a;
What does this code show? Did not call round?
The output is 1111111111111.1, which means 1111111111111.11 is converted to 1111111111111.1 during script compilation.
It is possible that the floating-point type of PHP cannot store 1111111111111.11 for precision reasons.
Didn't you read the official PHP instructions? "So never believe that the floating-point results are accurate to the last one."
What should I do with the numbers I'm trying to show in full?
You still did not read the official statement, the inside said very clearly, to find the answer to it
Round function No problem
$a = 1111111111111.11;echo $a;
Refer to PHP for a description of floating-point type accuracy.
http://www.php.net/manual/zh/language.types.float.php
$a = 1111111111111.11;
echo $a;
What does this code show? Did not call round?
The output is 1111111111111.1, which means 1111111111111.11 is converted to 1111111111111.1 during script compilation.
It is possible that the floating-point type of PHP cannot store 1111111111111.11 for precision reasons.
Didn't you read the official PHP instructions? "So never believe that the floating-point results are accurate to the last one."
What should I do with the numbers I'm trying to show in full?
You still did not read the official statement, the inside said very clearly, to find the answer to it
Ok,thanks
Floating-point numbers can only hold values of finite digits
PHP has provided a high-precision math function library BC, GMP