php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76824 number_format produces different signed result
Submitted: 2018-08-30 22:37 UTC Modified: 2018-08-30 22:48 UTC
From: jamesin dot hongkong dot 1 at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.2.9 OS:
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: jamesin dot hongkong dot 1 at gmail dot com
New email:
PHP Version: OS:

 

 [2018-08-30 22:37 UTC] jamesin dot hongkong dot 1 at gmail dot com
Description:
------------
One of our integration tests failed starting with PHP 7.2+ due to a different return value from number_format.

## Reproducible example

```
Output for 7.2.0 - 7.3.0beta2
0.00000

Output for 5.6.30, hhvm-3.18.5 - 3.22.0, 7.0.28 - 7.1.21
-0.00000
```

https://3v4l.org/WtLF8

Test script:
---------------
print number_format( -0.000000000004566, 5 );

Expected result:
----------------
-0.00000

Actual result:
--------------
0.00000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-30 22:48 UTC] danack@php.net
-Status: Open +Status: Not a bug
 [2018-08-30 22:48 UTC] danack@php.net
This is a deliberate change:

http://php.net/manual/en/migration72.incompatible.php

Previously, it was possible for the number_format() function to return -0. Whilst this is perfectly valid according to the IEEE 754 floating point specification, this oddity was not desirable for displaying formatted numbers in a human-readable form.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 07:00:02 2026 UTC