if (0.030! = (0.530-0.500+0+0))
{
$s = 0.530-0.500+0+0;
$s = 0.03-$s;
}
This is not equal??
It's not 0 after subtracting.
Is this PHP an alien calculation method?
Reply to discussion (solution)
Would you please cram your knowledge 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;
That's wrong.
Would you please cram your knowledge about floating-point numbers?
$f = (0.530-0.500+0+0) *1000;
$a = (0.030*1000);
$ssa = Doubleval ($a)-doubleval ($f);
It's wrong to write ... How did he figure that out?
What do you say?
Simple decimal fractions can not be converted to binary format in the case of a little bit of precision, floating-point numbers will never be accurate to the last, then in PHP, simple floating-point arithmetic is very likely to lose precision, resulting in confusion in the calculation results
What do you say?
Simple decimal fractions can not be converted to binary format in the case of a little bit of precision, floating-point numbers will never be accurate to the last, then in PHP, simple floating-point arithmetic is very likely to lose precision, resulting in confusion in the calculation results
How do you do that calculation like this?
Would you please cram your knowledge about floating-point numbers?
$f = (0.530-0.500+0+0) *1000;
$a = (0.030*1000);
$ssa = Doubleval ($a)-doubleval ($f);
It's wrong to write ... How did he figure that out?
This is not only PHP, Java also has a phenomenon
So PHP has 2 ways 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;
}
Put the variable in double quotes and it's OK.
Another way is to use the round function.
Looks like you're going to have to cram a little bit of knowledge into "effective numbers."