ID: 33009 User updated by: edelmar at ditech dot com dot br Reported By: edelmar at ditech dot com dot br Status: Open Bug Type: *Math Functions Operating System: Win XP PHP Version: 4.3.11 New Comment:
$d = 75.6 * 100; $d = (string)$d; echo floor($d).'<br>'; // prints 7560, wich is expected... how embarassing. Previous Comments: ------------------------------------------------------------------------ [2005-05-11 20:12:01] edelmar at ditech dot com dot br Description: ------------ Using PHP Version 4.3.11 on Windows xp (my development machine). I believe this behavior of floor function is a bug. The number 7560 passed to it is an integer and would not be changed by floor. I am using 100 times number because PHP has no function like 'truncate'. I want 2 decimals and there is no way to do it with regular functions. Its like 7560 has some special properties because this error does not happens with a lot of other numbers. Thank you. Reproduce code: --------------- echo (75.6 * 100).'<br>'; // prints 7560 - OK echo intval(75.6 * 100).'<br>'; // prints 7559 - ? echo (int)(75.6 * 100).'<br>'; // prints 7559 - ? echo floor(75.6 * 100).'<br>'; // prints 7559 - ? echo ceil(75.6 * 100).'<br>'; // prints 7560 - OK echo round(75.6 * 100).'<br>'; // prints 7560 - OK Expected result: ---------------- 7560 7560 7560 7560 7560 7560 Actual result: -------------- 7560 7559 7559 7559 7560 7560 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33009&edit=1