Bug #76220 [Opn->Nab]: Float variables comparison error

From: Date: Fri, 13 Apr 2018 18:29:28 +0000
Subject: Bug #76220 [Opn->Nab]: Float variables comparison error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214737@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76220&edit=1 ID: 76220 Updated by: aharvey@php.net Reported by: zyrlex at yandex dot ru Summary: Float variables comparison error -Status: Open +Status: Not a bug Type: Bug Package: Variables related Operating System: Ubuntu 16.04 PHP Version: 7.0.29 Block user comment: N Private report: N New Comment: 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: http://www.floating-point-gui.de/ Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2018-04-13 18:26:41] zyrlex at yandex dot ru Description: ------------ 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 var_dump($q1); var_dump($q2); 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: ---------------- float(2.7) float(2.7) 2.7 === 2.7 all ok Actual result: -------------- float(2.7) float(2.7) 2.7 !== 2.7 BUG ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76220&edit=1

« previous php.bugs (#214737) next »