Bug #67163 [Opn->Nab]: Return incorrect values.

From: Date: Wed, 30 Apr 2014 22:44:22 +0000
Subject: Bug #67163 [Opn->Nab]: Return incorrect values.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185530@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67163&edit=1 ID: 67163 Updated by: requinix@php.net Reported by: useful-soft at yandex dot ru Summary: Return incorrect values. -Status: Open +Status: Not a bug Type: Bug Package: Math related Operating System: Debian 7 64x PHP Version: 5.4.27 Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2014-04-30 21:15:30] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67163&edit=1

« previous php.bugs (#185530) next »