Bug #68473 [Opn->Nab]: number_format results on high numbers?
| From: | aharvey@php.net | Date: | Fri, 21 Nov 2014 18:10:09 +0000 |
| Subject: | Bug #68473 [Opn->Nab]: number_format results on high numbers? | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-188735@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68473&edit=1
ID: 68473
Updated by: aharvey@php.net
Reported by: php at kingsquare dot nl
Summary: number_format results on high numbers?
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: n/a
PHP Version: 5.6.3
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2014-11-21 16:46:09] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68473&edit=1