|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53549 Rounding twice yields a different result than rounding once
Submitted: 2010-12-15 11:03 UTC Modified: 2010-12-15 14:27 UTC
From: jeffreybolle at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.3.4 OS: ALL
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: jeffreybolle at gmail dot com
New email:
PHP Version: OS:


 [2010-12-15 11:03 UTC] jeffreybolle at gmail dot com
Rounding a float once should result in the same value as rounding it more than once.

Test script:
$float = -1.1368683772162E-13;
var_dump(round($float, 2));
var_dump(round(round($float, 2), 2));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-12-15 14:27 UTC]
-Status: Open +Status: Bogus
 [2010-12-15 14:27 UTC]
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
Thank you for your interest in PHP.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 17:01:30 2024 UTC