echo (int)(3980 / 100 * 50);
echo PHP_EOL;
echo (3980 / 100 * 50);
output
1989
1990
can someone explain this phenomenal for me?
echo (int)(3980 / 100 * 50);
echo PHP_EOL;
echo (3980 / 100 * 50);
output
1989
1990
can someone explain this phenomenal for me?
This is because of how floating point numbers are represented internally in binary IEEE 754
One may think (3980 / 100) will be 39.8
But infact, it will be represented exactly like 39.799999237060546875 and multiplying it by 50 it will be 1989.999961853
Now (int)1989.999961853.. you guessed it 1989