|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61624 round
Submitted: 2012-04-04 17:06 UTC Modified: 2012-04-05 13:49 UTC
From: gufophp at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.4.0 OS: win32
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gufophp at gmail dot com
New email:
PHP Version: OS:


 [2012-04-04 17:06 UTC] gufophp at gmail dot com
echo round(33.29999999999999715783,4);  // fail
echo "-";
echo round(33.29999999999999715783,2); // fail
echo "-";
echo round(33.29999999999999715783);  //ok
echo "-";
echo round(33.29999999999999715783,-1); //ok
echo "-";
echo round(55533.29999999999999715783,-2); //ok

Test script:

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-04-05 03:05 UTC] reeze dot xia at gmail dot com
Hi, gufophp:
  I can't reproduce it in both 5.4 & 5.3 | Win7 & Mac OS X. can you feedback more 
information about this?.

 [2012-04-05 13:08 UTC] gufophp at gmail dot com
change precision to
precision = 17
 [2012-04-05 13:49 UTC]
-Status: Open +Status: Not a bug
 [2012-04-05 13:49 UTC]
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:

Thank you for your interest in PHP.

The return value of round() is still a floating point number. If the precision is 
high enough, printing that float may result in seeing additional significant 
digits because of the imprecision inherent to floating point arithmetic.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 18:01:30 2024 UTC