3v4l.org

run code in 300+ PHP versions simultaneously
<?php function roundUp(float $num, int $precision): float { assert($precision > 0); $mul = [pow(10.0, $precision), 1.0 / (2 * pow(10.0, $precision - 1))]; return ($num * $mul[0] + $mul[1]) / $mul; } $as = [8.784512605042, 8.781512605042, 10.44445]; foreach ($as as $a) { //echo '#1: ' . number_format(number_format($a, 3), 2) . PHP_EOL; //echo '#2: ' . round(($a * 100 + 0.5) / 100.0, 2) . PHP_EOL; echo roundUp($a, 2) . PHP_EOL; }
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: Unsupported operand types: float / array in /in/PHA4N:9 Stack trace: #0 /in/PHA4N(16): roundUp(8.784512605042, 2) #1 {main} thrown in /in/PHA4N on line 9
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
140.89 ms | 405 KiB | 5 Q