Take the State of PHP 2026 Survey →

Prevent number_format() from returning negative zero View as Markdown

Implemented (PHP 7.2)
Authors
Craig Duncan php@duncanc.co.uk
Date
2017-04-01
Version
0.1
Source
wiki.php.net/rfc/number_format_negative_zero

Vote

Prevent number_format() from returning negative zero closed
Yes
14
No
1
15 voters
ashnazg Yes 2017-04-21 21:20
colinodell Yes 2017-04-22 11:45
danack Yes 2017-04-20 14:46
daverandom Yes 2017-04-20 08:56
dm Yes 2017-04-25 09:39
emir Yes 2017-04-22 15:48
galvao Yes 2017-04-27 10:20
kelunik Yes 2017-04-22 19:33
narf Yes 2017-04-25 16:07
ocramius Yes 2017-04-30 13:52
patrickallaert No 2017-04-20 20:57
peehaa Yes 2017-04-21 08:16
pollita Yes 2017-04-20 21:22
sammyk Yes 2017-04-21 20:52
trowski Yes 2017-04-22 04:15

Discussions on the mailing list

[RFC] Prevent number_format() from returning negative zero
by Craig Duncan · 2 messages
[RFC] [VOTE] Prevent number_format() from returning negative zero
by Craig Duncan · 3 messages

RFC text

Copied from wiki.php.net, last synchronized Oct 13, 2026 11:51 UTC

Introduction

Calling number_format(-0.00) returns string(1) “0”, however calling number_format(-0.01) returns string(2) “-0”.

As number_format() is commonly used for formatting numbers for human-readable display, this behaviour is unexpected.

Proposal

This RFC proposes keeping number_format() consistent and not displaying the sign when a number is rounded to zero.

Concerns

There was an argument that all floating point logic in PHP follows IEEE 754, where negative zero is valid.

However number_format() already prevents negative zero, so this isn't the case.

Backward Incompatible Changes

This change has BC concerns for anybody relying on the current behaviour, but this is thought to be incredibly minor and not unrealistic for a point release.

Proposed PHP Version(s)

PHP 7.2

Proposed Voting Choices

Simple Yes/No vote that doesn't change the language itself so requires 50% + 1 votes to get 'accepted'.

Vote: Prevent number_format() from returning negative zero — Yes: 14 · No: 1 (closed)

Implementation

Pull request: https://github.com/php/php-src/pull/2508

References

Initial discussion that led to this RFC's creation: https://externals.io/thread/522

Discussion thread: https://externals.io/thread/800

Voting thread: https://externals.io/thread/828