#30048 [Bgs]: round() and number_format() calculates wrong
| From: | derick@php.net | Date: | Fri, 10 Sep 2004 09:35:09 +0000 |
| Subject: | #30048 [Bgs]: round() and number_format() calculates wrong | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-65997@lists.php.net to get a copy of this message | ||
ID: 30048
Updated by: derick@php.net
Reported By: joerg dot klein at ifsam dot lu
Status: Bogus
Bug Type: *Math Functions
Operating System: win2000
PHP Version: 5.0.0
New Comment:
This bug system is not the place to provide solutions, see
http://php.net/support.php for that.
Previous Comments:
------------------------------------------------------------------------
[2004-09-10 11:15:54] joerg dot klein at ifsam dot lu
That's the cause, but not the solution.
------------------------------------------------------------------------
[2004-09-10 11:09:02] 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.
Thank you for your interest in PHP.
.
------------------------------------------------------------------------
[2004-09-10 10:48:00] joerg dot klein at ifsam dot lu
Description:
------------
I use a fomular as the first paramter and the result is wrong.
When brackets were set, the result is correct, but this makes no sense
to me.
Reproduce code:
---------------
echo round(0.35*90/100);
echo number_format(0.35*90/100, 2, ".", "");
to get the correct result I should use the following syntax:
echo round(0.35* (90/100) )
echo number_format(0.35* (90/100) , 2, ".", "");
Expected result:
----------------
0.32
0.32
Actual result:
--------------
0.31
0.31
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30048&edit=1