Bug #77675 [Opn->Nab]: Floating Value Bug

From: Date: Wed, 27 Feb 2019 14:31:19 +0000
Subject: Bug #77675 [Opn->Nab]: Floating Value Bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219755@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77675&edit=1 ID: 77675 Updated by: cmb@php.net Reported by: joni dot ttv at gmx dot de Summary: Floating Value Bug -Status: Open +Status: Not a bug Type: Bug Package: Math related Operating System: Debian, Mac OS PHP Version: 7.2.15 -Assigned To: +Assigned To: cmb 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: ------------------------------------------------------------------------ [2019-02-27 14:14:06] joni dot ttv at gmx dot de Description: ------------ Hello, there is a problem when adding float values: If you add 76.50 + 15.96 + 7.54 the result ist 100.00. If you var_dump the sum the result is also 100.00. But when you compare the sum and 100.00 the result is that they are not equal. If you swap the last two numbers, the sum is correct and also the comparison. Test script: --------------- <?php // Prints 100 var_dump(76.50 + 15.96 + 7.54); // Prints false (should be true) var_dump((76.50 + 15.96 + 7.54) == 100.00); // Prints false (should be true) var_dump((76.50 + 15.96 + 7.54) == (76.50 + 7.54 + 15.96)); Expected result: ---------------- 100.00 true true Actual result: -------------- 100.00 false false ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77675&edit=1

« previous php.bugs (#219755) next »