|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10131 Round error
Submitted: 2001-04-03 03:46 UTC Modified: 2001-04-03 11:16 UTC
From: woprog at hotmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.0.4pl1 OS: Red Hat Linux 6.2
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:
Solve the problem:
29 + 31 = ?
Subscribe to this entry?

 [2001-04-03 03:46 UTC] woprog at hotmail dot com
Execute this script:
	$a = 250.02;
	$b = 210.10;
	$c =  39.92;

	echo "a = $a<br>\n";
	echo "b = $b<br>\n";
	echo "c = $c<br>\n";

	echo "(b+c)-a = " . (($b+$c)-$a) . "<br>\n";

It SHOULD echo:
a = 250.02
b = 210.1
c = 39.92
(b+c)-a = 0

But it echoes on my machine:
a = 250.02
b = 210.1
c = 39.92
(b+c)-a = -2.8421709430404E-14

When you change the values, for example like this:
	$a = 250.022;
	$b = 210.101;
	$c =  39.921;
it echoes the correct values... if against all odds I am doing something wrong, please tell me....!

Marc, a very happy php programmer!

P.S. I compiled PHP with this command line:

'./configure' '--with-mysql' '--with-pgsql' '--with-esoob' '--with-magic-quotes' '--with-apxs' '--with-ftp' '--with-config-file-path=.'


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-03 04:15 UTC]
This is not a bug in PHP. it's how floating point math works, and there is nothing that we can do to change it.
The problem is that these floating point number are stored as a as good as possible representation of the numbers you use, but it's not possible to get them stored exactly as you want them to be.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Feb 28 14:01:28 2024 UTC