|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54730 comparison float
Submitted: 2011-05-13 20:01 UTC Modified: 2011-05-14 02:49 UTC
From: dancho at hahpss dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.3.6 OS: Linux
Private report: No CVE-ID: None
 [2011-05-13 20:01 UTC] dancho at hahpss dot com
view result

Test script:
	echo var_dump($v*100000)."\n";
	echo var_dump(round($v*100000,0));
	echo "\nIs equal ? "; 
	echo  ($v*100000==round($v*100000,0)) ? "true" : "false";

Expected result:


Is equal ? true

Actual result:


Is equal ? false


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-14 02:49 UTC]
-Status: Open +Status: Bogus
 [2011-05-14 02:49 UTC]
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.

If you would like to know more about "floats" and what IEEE
754 is, read this:

Thank you for your interest in PHP.

Try adding ini_set('precision',32); to the top of your test script and it should 
be clear why these are not equal.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 22:01:30 2024 UTC