php.net |  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
 [2012-04-04 17:06 UTC] gufophp at gmail dot com
Description:
------------
<?php
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:
---------------
33.29999999999999715783-33.29999999999999715783-33-30-55500

Expected result:
----------------
33.3-33.3-33-30-55500

Actual result:
--------------
33.29999999999999715783-33.29999999999999715783-33-30-55500

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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?.

Thanks
 [2012-04-05 13:08 UTC] gufophp at gmail dot com
php.ini
change precision to
precision = 17
 [2012-04-05 13:49 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2012-04-05 13:49 UTC] aharvey@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://www.floating-point-gui.de/

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 22 10:01:30 2024 UTC