Is PHP decimal calculation 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?
Reply to discussion (solution)
Please learn more about floating point numbers.
Even if I
$ F = (0.530-0.500 + 0 + 0) * 1000;
$ A = (0.030*1000 );
$ S = (0.530-0.500 + 0 + 0) * 1000;
$ Ssa = $ a-$ s;
This is also wrong.
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?
How can this problem be solved?
A simple decimal fraction cannot be converted to a binary format with a little bit of precision lost. floating point numbers will never be accurate to the last bit. in PHP, A simple floating-point number operation may result in loss of precision and confusion in the calculation results.
How can this problem be solved?
A simple decimal fraction cannot be converted to a binary format with a little bit of precision lost. floating point numbers will never be accurate to the last bit. in PHP, A simple floating-point number operation may result in loss of precision and confusion in the calculation results.
What should we do for such computing?
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.
It seems that you have to learn more about "effective number ".