|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33009 floor does not work with some integers as argument
Submitted: 2005-05-11 20:12 UTC Modified: 2005-05-11 21:03 UTC
From: edelmar at ditech dot com dot br Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 4.3.11 OS: Win XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: edelmar at ditech dot com dot br
New email:
PHP Version: OS:


 [2005-05-11 20:12 UTC] edelmar at ditech dot com dot br
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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-05-11 20:41 UTC] edelmar at ditech dot com dot br
$d = 75.6 * 100;
$d = (string)$d;
echo floor($d).'<br>'; // prints 7560, wich is expected... how embarassing.
 [2005-05-11 21:03 UTC]
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:
Thank you for your interest in PHP.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Feb 25 23:01:33 2024 UTC