ID: 21769 Comment by: kdeschen at ers dot ca Reported By: ltaupiac at lfdj dot com Status: Bogus Bug Type: Math related Operating System: Solaris 7 PHP Version: 4.3.0 New Comment:
Try these rounds. It give unexpected results on my web server. Apache/1.3.26 and PHP4.3.0 echo "<BR>".round(7026.005,2); --> 7026.01 echo "<BR>".round(7026.015,2); --> 7026.02 echo "<BR>".round(7026.025,2); --> 7026.02 echo "<BR>".round(7026.035,2); --> 7026.03 echo "<BR>".round(7026.045,2); --> 7026.05 echo "<BR>".round(7026.055,2); --> 7026.06 echo "<BR>".round(7026.065,2); --> 7026.06 echo "<BR>".round(7026.075,2); --> 7026.07 echo "<BR>".round(7026.085,2); --> 7026.09 echo "<BR>".round(7026.095,2); --> 7026.1 Previous Comments: ------------------------------------------------------------------------ [2003-01-20 03:54:13] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php http://www.php.net/manual/en/language.types.float.php ------------------------------------------------------------------------ [2003-01-20 03:48:54] ltaupiac at lfdj dot com <? $a=4.31; $b=5; $m=$a*$b ; $res=21.55 ; $v1=round(4.31*5,1); $v2=round($m,1) ; $v3=round($a*$b,1) ; $v4=round($res,1) ; $vbiz=round($a*$b,2) ; $r=$v2-$v1 ; $r2=$v3-$v1 ; $r3=$res-$m ; print ("<b>a=-$a- b=-$b- m=$a*$b=-$m- and res=$res") ."-<br></b>" ; print ("v1=round(4.31 * 5 , 1)=-$v1- -") . round($v1,1) ."-<br>" ; print ("v2=round(m, 1)=-$v2- -") . round($v2,1) ."-<br>" ; print ("v3=round(a*b , 1)=-$v3- -") . round($v3,1) ."-<br>" ; print ("v4=round(res , 1)=-$v4- -") . round($v4,1) ."-<br>" ; print ("expected round by 2 round... <br>") ; print ("vbiz=round($a*$b ,2)=$vbiz -- and round($vbiz, 1)=") . round($vbiz,1) ."<br><br>" ; print ("r=$v2-$v1=$r -good-<br>") ; print ("r2=$v3-$v1=$r2 -good-<br>") ; print ("unexpected result... <br>") ; print ("r3=$res-$m=$r3 -Huh ?-<br>") ; ?> will give that output a=-4.31- b=-5- m=4.31*5=-21.55- and res=21.55- v1=round(4.31 * 5 , 1)=-21.5- -21.5- v2=round(m, 1)=-21.5- -21.5- v3=round(a*b , 1)=-21.5- -21.5- v4=round(res , 1)=-21.6- -21.6- expected round by 2 round... vbiz=round(4.31*5 ,2)=21.55 -- and round(21.55, 1)=21.6 r=21.5-21.5=0 -good- r2=21.5-21.5=0 -good- unexpected result... r3=21.55-21.55=3.5527136788005E-15 -Huh ?- ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=21769&edit=1