Bug #71877 [Nab]: results not as expected
Edit report at https://bugs.php.net/bug.php?id=71877&edit=1
ID: 71877
Updated by: requinix@php.net
Reported by: iskandarm at live dot com
Summary: results not as expected
Status: Not a bug
Type: Bug
Package: *Math Functions
Operating System: linux
PHP Version: 5.5.33
Block user comment: N
Private report: N
New Comment:
My reply had a link which explains what is happening.
Previous Comments:
------------------------------------------------------------------------
[2016-03-22 12:43:31] 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 09:44:34] 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 09:36:33] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=71877&edit=1
Thread (4 messages)