php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31870 rounding negative numbers gives "-0"
Submitted: 2005-02-07 13:08 UTC Modified: 2005-02-08 14:19 UTC
From: amir at foresthc dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.0.3 OS: Debian woody
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: amir at foresthc dot com
New email:
PHP Version: OS:

 

 [2005-02-07 13:08 UTC] amir at foresthc dot com
Description:
------------
When rounding real negative numbers that should round to zero, the result is -0 (minus zero). This isn't a critical bug, but it's a nusanse hunting these down in places were the output reaches the user.

Reproduce code:
---------------
echo round(-0.1);

Expected result:
----------------
0

Actual result:
--------------
-0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-07 13:41 UTC] derick@php.net
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.
 
Thank you for your interest in PHP.

.
 [2005-02-07 13:57 UTC] amir at foresthc dot com
I was under the impression that zero has a unique floating point representation, and the only problem is with the sign flag.

Also the case at hand is not of "any mathematical operations" but of call to a mathematical function, and I am assuming there is one common piece of internal code that round() / number_format() / *printf() all use.

Obviously having no familiarity with PHP's internal code my assumptions could be completely incorrect.
 [2005-02-08 14:09 UTC] amir at foresthc dot com
re-opened to get a reponse.
 [2005-02-08 14:19 UTC] derick@php.net
This is not a discussion forum, and we just use the underlying  glibc.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Nov 23 21:00:01 2025 UTC