php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73581 number_format allows for -0.00
Submitted: 2016-11-22 15:30 UTC Modified: 2017-01-08 17:19 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bowersbros at gmail dot com Assigned:
Status: Wont fix Package: Math related
PHP Version: Irrelevant OS: Ubuntu 14.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
37 + 17 = ?
Subscribe to this entry?

 
 [2016-11-22 15:30 UTC] bowersbros at gmail dot com
Description:
------------
number_format fixes the number output from many decimals to a defined number. 

If you were to have a sufficiently small negative number, it will round and display "-0.00". I'd expect it to become zero, 

This has already been reported at https://bugs.php.net/bug.php?id=23866 however that is 13 years ago and it has not received a response.

Test script:
---------------
https://3v4l.org/oU2tg

<?php

$number = -1.15E-15;

var_dump($number);
var_dump(number_format($number, 2));

Expected result:
----------------
"0.00"

Actual result:
--------------
"-0.00"

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-11-22 15:31 UTC] bowersbros at gmail dot com
-Package: *General Issues +Package: Math related
 [2016-11-22 15:31 UTC] bowersbros at gmail dot com
Changed to be math
 [2017-01-08 17:19 UTC] krakjoe@php.net
-Status: Open +Status: Wont fix
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC