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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: iskandarm at live dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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: Thu Dec 26 11:01:30 2024 UTC