php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68473 number_format results on high numbers?
Submitted: 2014-11-21 16:46 UTC Modified: 2014-11-21 18:10 UTC
From: php at kingsquare dot nl Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.6.3 OS: n/a
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: php at kingsquare dot nl
New email:
PHP Version: OS:

 

 [2014-11-21 16:46 UTC] php at kingsquare dot nl
Description:
------------
We're seeing issues with number_format and strange behaviour. It seems to be rounding off / exceeding some kind of _undocumented_ limit ?


(related bug: 62792, but the response there is irrelevant since the PHP_INT_MAX isnt even reached in some cases and still the error persists? And before you go 'floating points and limited percision: this is an int, not a float... :) )

Test script:
---------------
<?php

echo PHP_INT_MAX.PHP_EOL;
echo number_format(PHP_INT_MAX, 0, '', '').PHP_EOL; // ?

echo '4'.PHP_EOL;
echo number_format(4, 0, '', '').PHP_EOL; // as expected

echo '23372036854775807'.PHP_EOL;
echo number_format('23372036854775807', 0, '', '').PHP_EOL; // still errors

echo '3372036854775807'.PHP_EOL;
echo number_format('3372036854775807', 0, '', '').PHP_EOL; // yeah! the same results :)

Expected result:
----------------
9223372036854775807
9223372036854775807
4
4
23372036854775807
23372036854775807
3372036854775807
3372036854775807

Actual result:
--------------
9223372036854775807
9223372036854775808
4
4
23372036854775807
23372036854775808
3372036854775807
3372036854775807

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-21 18:10 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-11-21 18:10 UTC] aharvey@php.net
This is expected behaviour: number_format expects a float, and therefore the first thing it does when you pass it any kind of number is convert it to a float. Since 23372036854775807 is greater than 2^53 (the highest integer that can be stored in a double precision float without losing precision), results may be... fuzzy.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 15:00:02 2026 UTC