php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30048 round() and number_format() calculates wrong
Submitted: 2004-09-10 10:48 UTC Modified: 2005-09-22 21:38 UTC
From: joerg dot klein at ifsam dot lu Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.0.0 OS: win2000
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: joerg dot klein at ifsam dot lu
New email:
PHP Version: OS:

 

 [2004-09-10 10:48 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-10 11:09 UTC] 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.

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 01:01:30 2024 UTC