Bug #64038 [Opn->Nab]: number_format isn't correct with big numbers
| From: | rasmus@php.net | Date: | Mon, 21 Jan 2013 16:18:00 +0000 |
| Subject: | Bug #64038 [Opn->Nab]: number_format isn't correct with big numbers | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-176155@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64038&edit=1
ID: 64038
Updated by: rasmus@php.net
Reported by: nicolas dot giraud at actiane dot com
Summary: number_format isn't correct with big numbers
-Status: Open
+Status: Not a bug
Type: Bug
Package: Unknown/Other Function
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Not much we can do about that. number_format() takes a float and you are
overflowing a float with your huge value. Since you already have it as a string,
you could just throw a regex at it. Something like:
preg_replace("/(?<=\d)(?=(\d{3})+(?!\d))/",",",$number);
Previous Comments:
------------------------------------------------------------------------
[2013-01-21 16:04:34] nicolas dot giraud at actiane dot com
Description:
------------
The number_format function don't give the good result with good format, maybe
because of cast in float that kills precision.
Test script:
---------------
<?php
$number = '123456789012345678901234567890';
$formatted = number_format($number, 2, '.', ' ');
echo $formatted;
?>
Expected result:
----------------
123 456 789 012 345 678 901 234 567 890.00
Actual result:
--------------
123 456 789 012 345 660 285 533 552 640.00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64038&edit=1