php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26954 0.1 - 01 = -2.77555756156E-017
Submitted: 2004-01-18 09:54 UTC Modified: 2004-01-18 10:00 UTC
From: choikh at oms dot cc Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.4 OS: window, linux
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: choikh at oms dot cc
New email:
PHP Version: OS:

 

 [2004-01-18 09:54 UTC] choikh at oms dot cc
Description:
------------
bug sample

<?
$tot = 0.3;
for($i=0;$i < 3; $i++)
{
    echo("==> $tot, ");
    $tot -= 0.1;
    echo("==> $tot<br>");

}
?>

result 
==> 0.3, ==> 0.2
==> 0.2, ==> 0.1
==> 0.1, ==> -2.77555756156E-017

why ?


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-18 10:00 UTC] derick@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.
 
Thank you for your interest in PHP.

/
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 12:01:30 2024 UTC