|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-09-02 09:28 UTC] scottmac@php.net
[2008-09-02 09:32 UTC] mattwil@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 20:00:01 2025 UTC |
Description: ------------ Rounding a calculated float gives bad results, rounding it as a string works as intended. Reproduce code: --------------- <?php echo "<pre>"; $total = 332.145; $substract = 274.5; $myVal = $total-$substract; var_dump($myVal); var_dump(round(57.645,2)); var_dump(round($myVal,2)); var_dump(round("$myVal",2)); echo "</pre>"; ?> Expected result: ---------------- float(57.645) float(57.65) float(57.65) float(57.65) Actual result: -------------- float(57.645) float(57.65) float(57.64) float(57.65)