Bug #54164 [Opn->Bgs]: Wrong Output Values
| From: | rasmus@php.net | Date: | Fri, 04 Mar 2011 22:33:34 +0000 |
| Subject: | Bug #54164 [Opn->Bgs]: Wrong Output Values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-159224@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=54164&edit=1
ID: 54164
Updated by: rasmus@php.net
Reported by: eskolife at hotmail dot com
Summary: Wrong Output Values
-Status: Open
+Status: Bogus
Type: Bug
Package: *General Issues
Operating System: Windows XP SP3
PHP Version: 5.3.5
Block user comment: N
Private report: N
New Comment:
Truncating floating point values is always dangerous because computers
do not
store floating point values precisely, so when you do
floor(4.999999999999999) you
are going to get 4, not 5. Use round() instead. You can read more about
it here:
http://en.wikipedia.org/wiki/IEEE_754-2008
Previous Comments:
------------------------------------------------------------------------
[2011-03-04 23:17:58] eskolife at hotmail dot com
Description:
------------
$Val = cos(deg2rad(60));
$Val = $Val * 10;
echo $Val.'---'.intval($Val).'<br>';
echo $Val.'---'.floor($Val);
then the output of this simple code should be:
5---5
5---5
but the real output is:
5---4
5---4
Test script:
---------------
<?php
$Val = cos(deg2rad(60));
$Val = $Val * 10;
echo $Val.'---'.intval($Val).'<br>';
echo $Val.'---'.floor($Val);
?>
Expected result:
----------------
5---5
5---5
Actual result:
--------------
5---4
5---4
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=54164&edit=1