Is PHP decimal calculation too boring? If (0.030 & nbsp ;! = & Nbsp; (0.530-0.500 + 0 + 0) {& nbsp; $ s & nbsp ;=& nbsp; 0.530-0.500 + 0 + 0; & nbsp; $ s & nbsp; = & nbsp; 0.03 & n is the calculation method of PHP decimal places too boring?
If (0.030! = (0.530-0.500 + 0 + 0 ))
{
$ S = 0.530-0.500 + 0 + 0;
$ S = 0.03-$ s;
}
Which is not equal ??
Not 0 After subtraction
Is PHP an alien computing method? Share:
------ Solution --------------------
Reference:
Quote: reference:
Please learn more about floating point numbers.
$ F = (0.530-0.500 + 0 + 0) * 1000;
$ A = (0.030*1000 );
$ Ssa = doubleval ($ a)-doubleval ($ f );
In this case, all of them are wrong... how does he calculate them?
This is not only true for php, but also for JAVA.
So there are two methods for PHP to solve floating point numbers.
One is
If (0.030! = (0.530-0.500 + 0 + 0 ))
{
$ S = 0.53-0.5;
$ S = 0.03-"$ s ";
Echo $ s;
}
Add up the variable's double quotation marks.
Another way is to use the round function.