|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62845 round returns -0
Submitted: 2012-08-17 09:30 UTC Modified: 2014-11-14 17:18 UTC
From: bradley dot lee80 at googlemail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.3.16 OS: Linux (Ubuntu)
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: bradley dot lee80 at googlemail dot com
New email:
PHP Version: OS:


 [2012-08-17 09:30 UTC] bradley dot lee80 at googlemail dot com
From manual page:

The round function returns -0 if the value is a negative value that should round to 0

Test script:
	echo round(-0.1);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-17 12:22 UTC]
Could you elaborate on why this would not be the expected behavior?

Also zero and negative zero are defined to compare equal, so I'm not sure whether this makes any difference in practice.
 [2012-08-17 12:24 UTC]
-Status: Open +Status: Not a bug
 [2012-08-17 12:24 UTC]
Computers use a standard described in IEEE-754 to handle floating point values. 
IEEE-754 uses -0 to describe values that approach 0 from a negative value. You 
will see the same thing in any language that uses the computer's built-in 
floating point mechanism. C, Python, Ruby, Perl, etc. For example in Python:

>>> round(-0.1)

You can read more about it at:
 [2014-11-14 14:34 UTC] hanskrentel at yahoo dot de
If the -0 is expected, then this indeed was wrong in some PHP versions:

$value = -2.2204460492503E-16;
$round = round($value, 4);

Output for 4.3.0 - 5.2.0, 5.3.4 - 5.3.6, hhvm-3.0.1 - 3.3.1
Output for 5.2.1 - 5.3.3, 5.3.7 - 5.6.3, php7@20140507 - 20141101

 [2014-11-14 17:18 UTC]
0 and -0 are equivalent, so if this is causing any sort of issue in your code you need to fix your code. You can read all about rounding in PHP here:
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Jun 04 19:01:23 2020 UTC