#47389 [Opn->Bgs]: With a for, after a while it miscounts.

From: Date: Sat, 14 Feb 2009 23:49:15 +0000
Subject: #47389 [Opn->Bgs]: With a for, after a while it miscounts.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-133835@lists.php.net to get a copy of this message
ID: 47389 Updated by: jani@php.net Reported By: php at mycel dot nl -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Ubuntu PHP Version: 5.2.9RC2 New Comment: 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 754 is, read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2009-02-14 20:57:41] php at mycel dot nl Description: ------------ With a for, if you count to 100, it will miscounts after a while. (with other computers it wil miscount earlier) Reproduce code: --------------- for ($i = 0; $i <= 800; $i += 0.01) { echo $i.'<br/>'; } Expected result: ---------------- 709.23 709.24 709.25 709.26 709.27 709.28 709.29 Actual result: -------------- 709.23 709.24 709.25 709.259999999 709.269999999 709.279999999 709.289999999 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47389&edit=1

« previous php.bugs (#133835) next »