rfc:number_format_negative_zero

PHP RFC: Prevent number_format() from returning negative zero

  • Version: 0.1
  • Date: 2017-04-01
  • Author: Craig Duncan php@duncanc.co.uk
  • Proposed version: PHP 7.2
  • Status: Implemented (in PHP 7.2)

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'.

Prevent number_format() from returning negative zero
Real name Yes No
ashnazg (ashnazg)  
colinodell (colinodell)  
danack (danack)  
daverandom (daverandom)  
dm (dm)  
emir (emir)  
galvao (galvao)  
kelunik (kelunik)  
narf (narf)  
ocramius (ocramius)  
patrickallaert (patrickallaert)  
peehaa (peehaa)  
pollita (pollita)  
sammyk (sammyk)  
trowski (trowski)  
Final result: 14 1
This poll has been closed.

Implementation

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

rfc/number_format_negative_zero.txt · Last modified: 2018/03/01 23:24 by carusogabriel