|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60557 ceil function bug
Submitted: 2011-12-19 03:38 UTC Modified: 2012-01-03 12:24 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: vividy163 at hotmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.3.8 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: vividy163 at hotmail dot com
New email:
PHP Version: OS:


 [2011-12-19 03:38 UTC] vividy163 at hotmail dot com
echo ceil(12000*(7/100));
it give me result 841.

Test script:
echo ceil(12000*(7/100));
it give me result 841.

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-12-20 00:55 UTC] anon at anon dot anon
Ceil is correct. Due to the underlying limitations of the floating point math, 7/100 is not a fraction which can be exactly represented, so the CPU chooses the closest possible value, and after multiplying the result is: 840.0000000000001136868377216160297393798828125

All programming languages implementing IEEE 754 (see: ) (which is most of them) will give 841 for this computation. In this specific case, just do the multiplication first (remove the extra brackets):

echo ceil(12000*7/100); // outputs: 840
 [2011-12-20 01:01 UTC] anon at anon dot anon
(And if you need a solution for the more general case, consider subtracting a tiny value just before calling ceil:)

echo ceil((12000*(7/100)) - 1e-8); // outputs: 840
 [2012-01-03 12:24 UTC]
-Status: Open +Status: Bogus
 [2012-01-03 12:24 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: Fri Jul 19 09:01:28 2024 UTC