-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Found out that the result was different when I execute below simple calculation.
$total_percentage = 33.4 + 33.3 + 33.3;
if ($total_percentage < 100) {
echo "Total less than " . $total_percentage;
} else {
if ($total_percentage > 100) {
echo "Total more than " . $total_percentage;
} else {
echo "Total is " . $total_percentage;
}
}
The result is weird: Total less than 100
But if I simply change the sequence to:
$total_percentage = 33.3 + 33.3 + 33.4;
Or value of first 2 to:
$total_percentage = 33.5 + 33.2 + 33.3;
Then both result is correct as expected: Total is 100
And if want to remain the sequence and i add with number_format:
if (number_format($total_percentage, 1) < 100) {
The result is also correct: Total is 100
This happen to all version of PHP from 4.0.6 to 8.3.10 and only if the value is 33.4 + 33.3 + 33.3;
What could be the possibility cause of this?