|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44277 when round() rounds a number -1<x<0, then it returns -0 (should be 0)
Submitted: 2008-02-28 00:28 UTC Modified: 2008-03-04 11:55 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: felix dot ospald at gmx dot de Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.5 OS: Windows XP
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: felix dot ospald at gmx dot de
New email:
PHP Version: OS:


 [2008-02-28 00:28 UTC] felix dot ospald at gmx dot de
This bug was already reported for Linux 3405 in 2000. Is this a bug or feature?

Reproduce code:
echo round(-0.1);

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-03 13:15 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.

 [2008-03-03 13:16 UTC]
# php -n -dprecision=32 -r '$a=-0.1; var_dump($a);var_dump(round($a));'

 [2008-03-04 11:55 UTC] felix dot ospald at gmx dot de
Yes I was aware of the limited precision.
But I'm still wondering if it is a good idea to have a positive and a negative zero as output of rounding operations that both should be mathematically the same zero which has noting to do with a limited float precision. Rounding is not like taking a left or right limit to the next integer. It also inherits problems in some cases e.g.: 

echo (((round(0.1).'EUR') == (round(-0.1).'EUR')) ? 'EQUAL' : 'NOT EQUAL');

gives: "NOT EQUAL"

MATLAB for example also doesn't have a negative zero here.

>> digits(32)
>> sym(-0.1,'d')
ans =
>> sym(round(-0.1),'d')
ans =
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 22 22:01:24 2023 UTC