3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $number = 90.1000; $number = round($number, 4); echo "Number is: ".$number.PHP_EOL; $number -= 0.1; echo "Number is: ".$number.PHP_EOL; $precision = 13; $epsilon = pow(0.1, $precision); $rounded = round($number, $precision); $roundedResult = $number; // echo "Test 1: ".$rounded.PHP_EOL; // echo "Test 2: ".abs($number - $rounded).PHP_EOL; if (abs($number - $rounded) < $epsilon) { $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 4.3.10 - 4.4.9, 5.0.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Number is: 90.1 Number is: 90 Source number: 90 Rounded result: 90 Inted result: 90
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/hc4YZ on line 9 Number is: 90.1PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/hc4YZ on line 13 Number is: 90PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/hc4YZ on line 42 Source number: 90PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/hc4YZ on line 43 Rounded result: 90PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/hc4YZ on line 44 Inted result: 90PHP_EOL