php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login go to bug id or search bugs for
Bug #40622 Submitted: round function 2007-02-24 21:36 UTC 2007-02-25 15:10 UTC bruno dot boccara at d2b dot com Not a bug Math related 4.4.5 windows 2003 Apache 2 No None
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.

[2007-02-24 21:36 UTC] bruno dot boccara at d2b dot com
```Description:
------------
round function gives wrong value.

Please do not send me to http://docs.sun.com/source/806-3568/ncg_goldberg.html, you have to admit that this is a bug !!!!!
if not, php CANNOT be use in production site with mathematical functions !!!

Reproduce code:
---------------
<?
// 140.25*(1-(34/100)) = 92.565

echo "formula = ". round(((140.25*(1-(34/100)))),2);echo "<br>";

echo "direct = ".round (92.565, 2);echo "<br>";

\$valeur = 140.25*(1-(34/100));

echo "value = ".round(\$valeur,2);echo "<br>";

settype(\$valeur,"string");
settype(\$valeur,"float");

echo "value2 = ".round(\$valeur,2);

?>

Expected result:
----------------
formula = 92.57
direct = 92.57
value = 92.57
value2 = 92.57

Actual result:
--------------
formula = 92.56 // WRONG !
direct = 92.57
value = 92.56  // WRONG !
value2 = 92.57

```

## History

[2007-02-24 22:05 UTC] johannes@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
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Thank you for your interest in PHP.

.
```
[2007-02-25 15:10 UTC] bruno dot boccara at d2b dot com
```Did I send an email to a robot ??