php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71877 results not as expected
Submitted: 2016-03-22 09:36 UTC Modified: 2016-03-22 12:57 UTC
From: iskandarm at live dot com Assigned:
Status: Not a bug Package: *Math Functions
PHP Version: 5.5.33 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
30 - 12 = ?
Subscribe to this entry?

 
 [2016-03-22 09:36 UTC] iskandarm at live dot com
Description:
------------
---
From manual page: http://www.php.net/function.ceil
---

i am trying to use ceil function , but for some numbers , i got unexpected results 

please find example in the test script .

Test script:
---------------
<?php
$dNumber = 1.1;
$dExponential = 100;
$x = ($dExponential*$dNumber);
var_dump($x);
var_dump(ceil($x));

Expected result:
----------------
expected results of the ceil is 110

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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-22 09:44 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-03-22 09:44 UTC] requinix@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://www.floating-point-gui.de/

Thank you for your interest in PHP.


 [2016-03-22 12:43 UTC] iskandarm at live dot com
hi , thanks for the quick reply , 
but if you try another number like .


<?php
$dNumber = 1.2;
$dExponential = 100;
$x = ($dExponential*$dNumber);
var_dump($x);
var_dump(ceil($x));

Expected result:
----------------
120

Actual result:
--------------
120



only the float of 110 is returning a wrong unexpected number .
 [2016-03-22 12:57 UTC] requinix@php.net
My reply had a link which explains what is happening.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 05:01:29 2024 UTC