ID: 44110 Updated by: [EMAIL PROTECTED] Reported By: dstuff at brainsware dot org -Status: Open +Status: Bogus Bug Type: *Math Functions Operating System: Any PHP Version: 5.2.5 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-02-13 16:14:03] dstuff at brainsware dot org Description: ------------ Some float values after multiplication by 100 (for elemination of decimal places) get rounded down by one after running intval() on the result. Reproduce code: --------------- <?php // prior calculation: echo intval(70.74 * 100); // testing for all numbers between 0 and 10 that do not hold the same value after type change for ($j = 0.00; $j < 10.0; $j = $j + 0.01) { $i = ($j); if (strval(intval($i * 100)) != strval(($i * 100))) { echo $i . ': ' . intval($i*100) . ' | ' . ($i * 100) . '<br />'; } } ?> Expected result: ---------------- Expected value after evaluation: 7047 Actual result: -------------- Actual value after evaluation: 7073 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=44110&edit=1