php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41338 ceil() gives strange results
Submitted: 2007-05-09 09:10 UTC Modified: 2007-05-09 09:19 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: kjarli at gmail dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.2.2 OS: Windows vista
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: kjarli at gmail dot com
New email:
PHP Version: OS:

 

 [2007-05-09 09:10 UTC] kjarli at gmail dot com
Description:
------------
when creating formulas, i encountered a strange bug:
this is the basic forumula:
ceil(user_hp * 1.1)

when user_hp = 100 you get the following formula

ceil(100*(110/100)) in my script.

this will result 111 instead of 110


Reproduce code:
---------------
<?php
$lol1 = ceil(100 * (110 / 100));
$lol2 = ceil(100 * 1.1);
$lol3 = ceil(110);
$lol4 = ceil(110.0);

echo $lol1;
?> 
<br />
<?php
echo $lol2;
?> 
<br />
<?php
echo $lol3;
?> 
<br />
<?php
echo $lol4;
?>

Expected result:
----------------
110
110
110
110


Actual result:
--------------
111
111
110
110

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-09 09:19 UTC] tony2001@php.net
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.


 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Aug 19 08:04:05 2022 UTC