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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Tue May 21 21:01:33 2024 UTC