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 Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
26 - 26 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Thu Mar 28 16:01:29 2024 UTC