3v4l.org

run code in 300+ PHP versions simultaneously
<?php function bround($dVal,$iDec) { // banker's style rounding or round-half-even // (round down when even number is left of 5, otherwise round up) // $dVal is value to round // $iDec specifies number of decimal places to retain static $dFuzz=0.00001; // to deal with floating-point precision loss $iRoundup=0; // amount to round up by $iSign=($dVal!=0.0) ? intval($dVal/abs($dVal)) : 1; $dVal=abs($dVal); // get decimal digit in question and amount to right of it as a fraction $dWorking=$dVal*pow(10.0,$iDec+1)-floor($dVal*pow(10.0,$iDec))*10.0; $iEvenOddDigit=floor($dVal*pow(10.0,$iDec))-floor($dVal*pow(10.0,$iDec-1))*10.0; if (abs($dWorking-5.0)<$dFuzz) $iRoundup=($iEvenOddDigit & 1) ? 1 : 0; else $iRoundup=($dWorking>5.0) ? 1 : 0; return $iSign*((floor($dVal*pow(10.0,$iDec))+$iRoundup)/pow(10.0,$iDec)); } echo bround(10.005); ?>
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught ArgumentCountError: Too few arguments to function bround(), 1 passed in /in/F40HV on line 21 and exactly 2 expected in /in/F40HV:3 Stack trace: #0 /in/F40HV(21): bround(10.005) #1 {main} thrown in /in/F40HV on line 3
Process exited with code 255.
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20
Warning: Missing argument 2 for bround(), called in /in/F40HV on line 21 and defined in /in/F40HV on line 3 Notice: Undefined variable: iDec in /in/F40HV on line 14 Notice: Undefined variable: iDec in /in/F40HV on line 14 Notice: Undefined variable: iDec in /in/F40HV on line 15 Notice: Undefined variable: iDec in /in/F40HV on line 15 Notice: Undefined variable: iDec in /in/F40HV on line 18 Notice: Undefined variable: iDec in /in/F40HV on line 18 10

preferences:
144.42 ms | 403 KiB | 213 Q