|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2011-08-27 06:53 UTC] forez84 at gmail dot com
Description:
------------
<?php
for ($i=0; $i<100; $i=$i+0.1) {
echo $i.'|';
}
?>
this produces something like:
0|0.1|0.2|0.3|0.4|0.5|0.6|0.7|0.8|0.9...
...53.6|53.7|53.8|53.9|54|54.1|54.200000000001|54.300000000001|54.400000000001|54.500000000001|...
...66.200000000001|66.300000000001|66.400000000001|66.5|66.6|66.7|66.8|66.9|67|67.1|67.2|...
...83.7|83.8|83.9|84|84.099999999999|84.199999999999|84.299999999999...
...99.799999999999|99.899999999999|99.999999999999|
I believe it makes one more iteration then it should.
Test script:
---------------
<?php
for ($i=0; $i<100; $i=$i+0.1) {
echo $i.'|';
}
?>
Expected result:
----------------
0|0.1|0.2|0.3|...53.9|54|54.1|54.2|54.3|54.4|...99.9|
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 16:00:01 2025 UTC |
<?php for ($i=0; $i<100; $i=$i+0.1) { echo $i.'|'; } ?> this produces something like: 0|0.1|0.2|0.3|0.4|0.5|0.6|0.7|0.8|0.9... ...53.6|53.7|53.8|53.9|54|54.1|54.200000000001|54.300000000001|54.400000000001|54.500000000001|... ...66.200000000001|66.300000000001|66.400000000001|66.5|66.6|66.7|66.8|66.9|67|67.1|67.2|... ...83.7|83.8|83.9|84|84.099999999999|84.199999999999|84.299999999999... ...99.799999999999|99.899999999999|99.999999999999| I believe it makes one more iteration than it should.