|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13241 round() failed elementary level math
Submitted: 2001-09-10 18:08 UTC Modified: 2001-09-10 18:56 UTC
From: cnewbill at elementalrain dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.0.6 OS: Linux 2.4.x
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: cnewbill at elementalrain dot com
New email:
PHP Version: OS:


 [2001-09-10 18:08 UTC] cnewbill at elementalrain dot com
[Post from PHP-DEV]


$x = 10.95;
$y = 0.70;

$e = $x*$y;

print "Discounted price = $e\n";


$z = round($e, 2);


print "Rounded Price = $z\n";

// this works grrr

$x = round(7.665, 2);

print "Working example of round = $x\n";



[cnewbill@storm cnewbill]$ php -q t.php
Discounted price = 7.665
Rounded Price = 7.66
Working example of round = 7.67
[cnewbill@storm cnewbill]$ php -v

Which is wrong, it should be 7.67.  If I don't do the multiplication and
simply send round 7.665 it works right!!??

Any ideas?



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-10 18:55 UTC]
Floats are inaccurate, by doing some math on them, you ended up with 7.6649999999999999999 or something, which is correctly rounded DOWN.

Simply don't use floats if it needs to accurate. RTFM on floats, you'll more info there.
 [2001-09-10 18:56 UTC]
The language-monster has eaten up my verbs, sorry for that ;-)

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 28 14:01:28 2024 UTC