php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21769 round error
Submitted: 2003-01-20 03:48 UTC Modified: 2003-01-20 03:54 UTC
From: ltaupiac at lfdj dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.0 OS: Solaris 7
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ltaupiac at lfdj dot com
New email:
PHP Version: OS:

 

 [2003-01-20 03:48 UTC] 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 ?-

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-20 03:54 UTC] derick@php.net
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 08:01:29 2024 UTC