Bug #70261 [Opn->Nab]: Error when comparing floating point

From: Date: Thu, 13 Aug 2015 18:59:16 +0000
Subject: Bug #70261 [Opn->Nab]: Error when comparing floating point
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195192@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70261&edit=1 ID: 70261 Updated by: rasmus@php.net Reported by: egdn2004 at gmail dot com Summary: Error when comparing floating point -Status: Open +Status: Not a bug Type: Bug Package: Reproducible crash Operating System: All PHP Version: Irrelevant 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: ------------------------------------------------------------------------ [2015-08-13 18:24:11] egdn2004 at gmail dot com Test script: --------------- <?php $var1 = 9.22; $var2 = 9.20; $var_test = $var2 + 0.02; if ($var1 > $var_test) { echo "WRONG\n"; } else { echo "OK\n"; } if (9.22 > 9.20 + 0.02) { echo "WRONG"; } else { echo "OK"; } Expected result: ---------------- OK OK Actual result: -------------- WRONG WRONG ------------------------------------------------------------------------ [2015-08-13 18:13:08] egdn2004 at gmail dot com Description: ------------ Error when comparing floating point with two decimal places Test script: --------------- <?php if (9.2 > 9.0 + 0.2) { echo 'WRONG'; } else { echo 'OK'; } Expected result: ---------------- OK Actual result: -------------- WRONG ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70261&edit=1

« previous php.bugs (#195192) next »