#44311 [Opn->Bgs]: Bug in arithmetic operation: 173.42-173.42=2.8421709430404E-014

From: Date: Sun, 02 Mar 2008 15:04:51 +0000
Subject: #44311 [Opn->Bgs]: Bug in arithmetic operation: 173.42-173.42=2.8421709430404E-014
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-122841@lists.php.net to get a copy of this message
ID: 44311 Updated by: scottmac@php.net Reported By: sawas at poczta dot onet dot pl -Status: Open +Status: Bogus Bug Type: Math related Operating System: WinXP, Debian PHP Version: 4.4.8 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://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2008-03-02 13:25:44] sawas at poczta dot onet dot pl Description: ------------ I found a bug in arithmetic operation. Simple subtraction of amounts gives inaccurate result. Reproduce code: --------------- $a = 160.00 + 5.90 + 7.52; $b = 173.42; print $a-$b; Expected result: ---------------- 0 Actual result: -------------- 2.8421709430404E-014 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44311&edit=1

« previous php.bugs (#122841) next »