|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8164 weird subtraction result
Submitted: 2000-12-08 06:23 UTC Modified: 2000-12-09 02:15 UTC
From: c dot becker at provi dot de Assigned:
Status: Closed Package: Math related
PHP Version: 4.0.0 OS: SuSE Linux 6.3
Private report: No CVE-ID: None
 [2000-12-08 06:23 UTC] c dot becker at provi dot de
I don't know, if this is a Math related problem,
it is a simple subtraction problem.

If I type this 

$one = "555.6";
$two = "555.5";

$result = $one - $two;

echo $result;

the result in my browser is


This occurs with more numbers than above.
So, what is my problem?


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-08 11:49 UTC] c dot becker at provi dot de
this won't work, either.

$one = 555.6;
$two = 555.5;

$result = $one - $two;

echo $result;

 [2000-12-09 02:15 UTC]
This is not a PHP bug, it's the age old issue of the accuracy of a floating point number. Since a computer cannot store a number *precisely*, it stores as close as it can get. When you do math operations on such a number, the difference (aka rounding error) between what you entered and what the computer stored is exagerated. See for a bit of an explanation.

Try using printf( "%.1f", $result );

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 12:01:29 2024 UTC