The 55 isn’t actually 55. You can verify that easily:
<?php
$x = (40 * (10 / 100 + 1)); // 44
$y = (50 * (10 / 100 + 1)); // 55
echo '$x == 44: ' . ($x == 44 ? 'True' : 'False') . "\n";
echo '$y == 55: ' . ($y == 55 ? 'True' : 'False') . "\n";
echo '$y > 55: ' . ($y > 55 ? 'True' : 'False') . "\n";
echo $y - 55;
Yields:
$x == 44: True
$y == 55: False
$y > 55: True
7.105427357601E-15
As you can see the difference is tiny (7.1 * 10^-15) but that still makes it larger than 55, so ceil
will round it up.
The reason you just see 55
is because echoing it will convert the float into a string:
String conversion is automatically done in the scope of an expression where a string is needed. This happens when using the echo or print functions, or when a variable is compared to a string.
For this conversion the standard truncating behavior will cut off the digits at some point. This is configured by the precision
configuration parameter and defaults to 14. You can avoid this behavior by using sprintf
with a custom precision:
echo sprintf('%.50f', $y);
// 55.00000000000000710542735760100185871124267578125000