php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47389 With a for, after a while it miscounts.
Submitted: 2009-02-14 20:57 UTC Modified: 2009-02-14 23:49 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: php at mycel dot nl Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.2.9RC2 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at mycel dot nl
New email:
PHP Version: OS:

 

 [2009-02-14 20:57 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-02-14 23:49 UTC] jani@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 02:01:29 2024 UTC