#40304 [Bgs]: Round() function strange issue
| From: | tjouanne at hotmail dot com | Date: | Thu, 01 Feb 2007 10:21:56 +0000 |
| Subject: | #40304 [Bgs]: Round() function strange issue | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-108295@lists.php.net to get a copy of this message | ||
ID: 40304
User updated by: tjouanne at hotmail dot com
Reported By: tjouanne at hotmail dot com
Status: Bogus
Bug Type: *General Issues
Operating System: Linux and windows
PHP Version: 4.4.4
New Comment:
Do you know if there is a function in php who works correctly for this
need?
Previous Comments:
------------------------------------------------------------------------
[2007-02-01 10:13:39] derick@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://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
.
------------------------------------------------------------------------
[2007-02-01 10:02:13] tjouanne at hotmail dot com
Description:
------------
round number with round() function give strange result:
9.815,609.815,4690.815,14609.815,6.735,56.735,1056.735,11056.735
produce
9.82
609.82
4609.81
14609.82
6.74
56.74
1056.73
11056.74
Why it's become 81 or 73 instead of 82 or 74
Reproduce code:
---------------
<?
echo (round("9.815", 2)."<BR>");
echo (round("609.815", 2)."<BR>");
echo (round("4609.815", 2)."<BR>");
echo (round("14609.815", 2)."<BR>");
echo (round("6.735", 2)."<BR>");
echo (round("56.735", 2)."<BR>");
echo (round("1056.735", 2)."<BR>");
echo (round("11056.735", 2)."<BR>");
?>
Expected result:
----------------
9.82
609.82
4609.82
14609.82
6.74
56.74
1056.74
11056.74
Actual result:
--------------
9.82
609.82
4609.81
14609.82
6.74
56.74
1056.73
11056.74
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40304&edit=1