php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43640 Wrong Result Adding Float (2.8 not 2.8)
Submitted: 2007-12-20 01:04 UTC Modified: 2007-12-20 02:11 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: tyokoo at monadel dot com dot au Assigned:
Status: Closed Package: Math related
PHP Version: 5.2.5 OS: Windows2003R2 Standard
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tyokoo at monadel dot com dot au
New email:
PHP Version: OS:

 

 [2007-12-20 01:04 UTC] tyokoo at monadel dot com dot au
Description:
------------
If you assign 2.8 on PHP you get:
2.79999999999999982236431605997495353221893310546875

if you do:
  $n = 2.8;
  $n = $n+$n+$n+$n+$n+$n+$n+$n+$n+$n;
and compare:
  $n == 28
will be false.

2.8 is 2.8.
Nothing more or less.





Reproduce code:
---------------
$n = 2.8;
echo serialize($n).'<br />';

$n = $n+$n+$n+$n+$n+$n+$n+$n+$n+$n;

if ($n == 28) {
  echo 'right';
} else {
  echo 'wrong';
}

Expected result:
----------------
d:2.8;
right

Actual result:
--------------
d:2.79999999999999982236431605997495353221893310546875;
wrong 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-20 02:11 UTC] tyokoo at monadel dot com dot au
See FYI: http://au.php.net/float
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 18:01:29 2024 UTC