php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62792 number_format with largue numbers is broken
Submitted: 2012-08-10 13:39 UTC Modified: 2012-08-13 11:15 UTC
From: brodanoel at gmail dot com Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.3.15 OS: Red Hat
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: brodanoel at gmail dot com
New email:
PHP Version: OS:

 

 [2012-08-10 13:39 UTC] brodanoel at gmail dot com
Description:
------------
Using the number_format function with largue numbers, the value returned is the real + 1

Test script:
---------------
number_format(9999999999999999999, 0, '', '.')

Expected result:
----------------
9.999.999.999.999.999.999

Actual result:
--------------
10.000.000.000.000.000.000

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-11 04:40 UTC] aharvey@php.net
Floating point values have a limited precision. Hence a value might 
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly 
printing it without any mathematical operations.

If you would like to know more about "floats" and what IEEE
754 is, read this:
http://www.floating-point-gui.de/

Thank you for your interest in PHP.


 [2012-08-11 04:40 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-08-13 10:29 UTC] brodanoel at gmail dot com
But... Here not have float numbers. Is a Integer.
And is not necesary a Mathematical operation in this function (number_format)
 [2012-08-13 11:15 UTC] aharvey@php.net
9999999999999999999 is beyond the maximum value an integer variable can hold in 
PHP, and is automatically converted to a floating point value.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 12:01:30 2024 UTC