|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26526 Unexpected behavior with ceil()
Submitted: 2003-12-04 15:16 UTC Modified: 2003-12-04 15:35 UTC
From: vince at blue-box dot net Assigned:
Status: Not a bug Package: Math related
PHP Version: 4CVS-2003-12-04 (stable) OS: FreeBSD 4.8-RELEASE-p13
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: vince at blue-box dot net
New email:
PHP Version: OS:


 [2003-12-04 15:16 UTC] vince at blue-box dot net
When using certain integers derived from multiplying integers and floating point numbers with ceil(), ceil() will increment the number even though it shouldn't be.

Reproduce code:

$value = 6*.029*1000;
echo "value = $value\n";

$value = ceil($value);
echo "value = $value\n";


Expected result:
Since 6*.029*1000 comes out to be exactly 174, I would expect the output of the above script to be:

value = 174
value = 174

Actual result:
value = 174
value = 175

It seems like if this were a floating point precision problem the first echo statement in the code example would produce something like:

value = 174.000000000000000000001


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-12-04 15:35 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.
Thank you for your interest in PHP.

# cat t.php 

ini_set('precision', 20);
$value = 6*.029*1000;
echo "value = $value\n";


# php t.php 
value = 174.00000000000002842

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 07:01:30 2024 UTC