ID: 45897 Updated by: [EMAIL PROTECTED] Reported By: hengkhee at gmail dot com -Status: Open +Status: Bogus Bug Type: Math related Operating System: UBuntu 8.04, CentOS 5.0 PHP Version: 5.2.4 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. $ php -dprecision=32 -r 'var_dump(0.15*3*100);' float(44.999999999999992894572642398998) Previous Comments: ------------------------------------------------------------------------ [2008-08-23 13:14:38] hengkhee at gmail dot com The php version on ------------ Ubuntu 8.04: ------------ PHP 5.2.4-2ubuntu5.3 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul 23 2008 06:46:18) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies ------------ CentOS: ------------ PHP 5.2.6 (cli) (built: Jul 29 2008 20:48:49) Copyright (c) 1997-2008 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with Zend Extension Manager v1.2.2, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies ------------------------------------------------------------------------ [2008-08-23 13:09:02] hengkhee at gmail dot com Description: ------------ - Modulus error, please refer to code. - Using default package/installation from Ubuntu 8.04 Server/Desktop and CentOS 5.0 - Using default php.ini from distro. Reproduce code: --------------- $var1 = 0.15 * 3 * 100; echo ($var1 % 5); # Output "4", unexpected result echo ((0.15 * 3 * 100) % 5); # Output "4", unexpected result echo (45.00 % 5); # Output "0", correct result echo (45 % 5); # Output "0", correct result echo (($var1."") % 5); # Output "0", correct result Expected result: ---------------- Correct result = "0" for all above sample. Actual result: -------------- Please refer to above sample code. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45897&edit=1