|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-12-04 15:16 UTC] vince at blue-box dot net
Description: ------------ When using certain integers derived from multiplying integers and floating point numbers with ceil(), ceil() will increment the number even though it shouldn't be. Reproduce code: --------------- <?php $value = 6*.029*1000; echo "value = $value\n"; $value = ceil($value); echo "value = $value\n"; ?> Expected result: ---------------- Since 6*.029*1000 comes out to be exactly 174, I would expect the output of the above script to be: value = 174 value = 174 Actual result: -------------- value = 174 value = 175 It seems like if this were a floating point precision problem the first echo statement in the code example would produce something like: value = 174.000000000000000000001 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 23:00:01 2025 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. Thank you for your interest in PHP. # cat t.php <?php ini_set('precision', 20); $value = 6*.029*1000; echo "value = $value\n"; ?> # php t.php value = 174.00000000000002842