3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $number = 3.0000000002; $precision = 12; $delta = pow(0.1, $precision); $rounded = round($number, 8);//$precision); if (abs($number - $rounded) < $delta) { $roundedResult = intval($number); } $intedResult = $number; if ((int) $number == $number){ $intedResult = (int) $number; } echo "Delta is : ".$delta.PHP_EOL; echo "Source number: ".$number.PHP_EOL; echo "Rounded result: ".$roundedResult.PHP_EOL; echo "Inted result: ".$intedResult.PHP_EOL;
Output for 5.5.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Delta is : 1.0E-12 Source number: 3.0000000002 Notice: Undefined variable: roundedResult in /in/kYvp6 on line 27 Rounded result: Inted result: 3.0000000002
Output for 5.2.2 - 5.4.45
Delta is : 1.0E-12 Source number: 3.0000000002 Rounded result: Inted result: 3.0000000002
Output for 4.3.10 - 4.4.9, 5.0.2 - 5.2.1
Delta is : 1E-12 Source number: 3.0000000002 Rounded result: Inted result: 3.0000000002
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
Delta is : 1E-12PHP_EOLSource number: 3.0000000002PHP_EOLRounded result: PHP_EOLInted result: 3.0000000002PHP_EOL