php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67163 Return incorrect values.
Submitted: 2014-04-30 21:15 UTC Modified: 2014-04-30 22:44 UTC
From: useful-soft at yandex dot ru Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.4.27 OS: Debian 7 64x
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: useful-soft at yandex dot ru
New email:
PHP Version: OS:

 

 [2014-04-30 21:15 UTC] useful-soft at yandex dot ru
Description:
------------
Tested in PHP 5.4.27 and PHP 5.4.15

Return incorrect values.

Test script:
---------------
echo number_format( 1.7976931348623157e+308, 2 );
// Result: 179,769,313,486,231,570,814,527,423,731,704,356,798,070,567,525,844,996,598,917,476,803,157,260,780,028,538,760,589,558,632,766,878,171,540,458,953,514,382,464,234,321,326,889,464,182,768,467,546,703,537,516,986,049,910,576,551,282,076,245,490,090,389,328,944,075,868,508,455,133,942,304,583,236,903,222,948,165,808,559,332,123,348,274,797,826,204,144,723,168,738,177,180,919,299,881,250,404,026,184,124,858,368.00

echo round( 1.7976931348623157e+308, 2 );
// Result: 1.7976931348623157e+308




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-04-30 22:44 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-04-30 22:44 UTC] requinix@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.

Besides, 1.7976931348623157e+308 rounded to two decimal places is still 1.7976931348623157e+308. If you want string output then use a different function - such as number_format() with an empty string as the thousands separator.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 17:01:29 2024 UTC