Bug #76515 [Opn->Nab]: if you multiply 1.9 by 3 and if you ta subtract the same the result is not zero

From: Date: Fri, 22 Jun 2018 02:35:16 +0000
Subject: Bug #76515 [Opn->Nab]: if you multiply 1.9 by 3 and if you ta subtract the same the result is not zero
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-215846@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76515&edit=1 ID: 76515 Updated by: requinix@php.net Reported by: manuel dot cs dot hr at gmail dot com Summary: if you multiply 1.9 by 3 and if you ta subtract the same the result is not zero -Status: Open +Status: Not a bug Type: Bug Package: Math related Operating System: Linux PHP Version: 7.0Git-2018-06-22 (Git) 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-06-22 02:34:03] manuel dot cs dot hr at gmail dot com Description: ------------ if you multiply 1.9 by 3 the result is 5.7 and if you ta subtract the result 5.7 the answer is not zero Test script: --------------- <?php $qty = 3; $val1 = 1.9; $discount = 5.7; $items_ = $val1 * $qty ; $result = $items_ - $discount; var_dump($result); ?> Expected result: ---------------- $result = 0; ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76515&edit=1

« previous php.bugs (#215846) next »