|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76220 Float variables comparison error
Submitted: 2018-04-13 18:26 UTC Modified: 2018-04-13 18:29 UTC
From: zyrlex at yandex dot ru Assigned:
Status: Not a bug Package: Variables related
PHP Version: 7.0.29 OS: Ubuntu 16.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: zyrlex at yandex dot ru
New email:
PHP Version: OS:


 [2018-04-13 18:26 UTC] zyrlex at yandex dot ru
Comparison of variables does not give a positive result
2.7 !== 2.7

Test script:
$q1 = floatval(2.7);
$q2 = floatval(18*0.15); //18*0.15 = 2.7


if($q1 === $q2) {
	echo '2.7 === 2.7 all ok';	
} else {
	echo '2.7 !== 2.7 BUG'; //Why?

if($q1 == $q2) {
	echo '2.7 == 2.7 all ok';

Expected result:
2.7 === 2.7 all ok

Actual result:
2.7 !== 2.7 BUG


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-13 18:29 UTC]
-Status: Open +Status: Not a bug
 [2018-04-13 18:29 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.

 [2018-04-14 05:29 UTC] zyrlex at yandex dot ru
I suspect that is the case, thanks for the reply.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 24 16:01:32 2024 UTC