|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-04-25 20:43 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Dec 20 09:00:01 2025 UTC |
Description: ------------ In loops like While and For with increases with point decimal fails the precision. Reproduce code: --------------- $i=71; $i2 = 82; $increases = .1; for($i; $i <= $i2; $i = $i + $increases) { echo "$i<br>"; } //**** or ****** $i=1.5; $i2 = 2; $increases = .001; while($i <= $i2) { echo "$i<br>"; $i = $i + $increases; } Expected result: ---------------- with $i=71; $i2 = 82; $increases = .1; it must be: 71 71.1 . . . 81.9 82 *************** with $i=1.5; $i2 = 2; $increases = .001; it must be: 1.5 1.501 1.502 . . . 1.999 2 Actual result: -------------- both with $i=71; $i2 = 82; generates: 71 71.1 . . 79.8 79.899999999999 79.999999999999 . . 81.899999999999 81.999999999999 *************** both with $i=1.5; $i2 = 2; $increases = .001; generates: 1.5 1.501 1.502 . . 1.954 1.9549999999999 1.9559999999999 . . 1.9989999999999 1.9999999999999