3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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.2.0
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.3.21 - 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