# RFC: Prevent number_format() from returning negative zero

- Status: Implemented (PHP 7.2)
- Authors: Craig Duncan php@duncanc.co.uk
- Date: 2017-04-01
- Version: 0.1
- Original: https://wiki.php.net/rfc/number_format_negative_zero
- Page: https://externals.io/rfc/number_format_negative_zero
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

## Votes

### Prevent number_format() from returning negative zero (closed)

Yes: 14 · No: 1

Voters: ashnazg (Yes), colinodell (Yes), danack (Yes), daverandom (Yes), dm (Yes), emir (Yes), galvao (Yes), kelunik (Yes), narf (Yes), ocramius (Yes), patrickallaert (No), peehaa (Yes), pollita (Yes), sammyk (Yes), trowski (Yes)

## Discussions on the mailing list

- [\[RFC\] Prevent number_format() from returning negative zero](https://externals.io/message/98719.md) — started on 2017-04-01, 2 messages
- [\[RFC\] \[VOTE\] Prevent number_format() from returning negative zero](https://externals.io/message/98823.md) — started on 2017-04-19, 3 messages

---

## 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>
