From: [EMAIL PROTECTED] Operating system: Solaris 7 PHP version: 4.3.0 PHP Bug Type: Math related Bug description: round error
<? $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 bug report at http://bugs.php.net/?id=21769&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=21769&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=21769&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=21769&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=21769&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=21769&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=21769&r=support Expected behavior: http://bugs.php.net/fix.php?id=21769&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=21769&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=21769&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=21769&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=21769&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=21769&r=dst IIS Stability: http://bugs.php.net/fix.php?id=21769&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=21769&r=gnused