Bug #52016 [Opn->Bgs]: cast a float variable rounds the value
| From: | degeberg@php.net | Date: | Mon, 07 Jun 2010 14:47:39 +0000 |
| Subject: | Bug #52016 [Opn->Bgs]: cast a float variable rounds the value | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-151158@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52016&edit=1
ID: 52016
Updated by: degeberg@php.net
Reported by: nbourdial at x-prime dot com
Summary: cast a float variable rounds the value
-Status: Open
+Status: Bogus
Type: Bug
Package: Scripting Engine problem
Operating System: Linux 2.6.26-2-686
PHP Version: 5.2.13
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2010-06-07 16:43:51] nbourdial at x-prime dot com
Description:
------------
Hi,
when I cast a float variable to int, the final value is not correct for
some values.
Test script:
---------------
var_dump((int)("37.91"*100));
Expected result:
----------------
int(3791)
Actual result:
--------------
int(3790)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52016&edit=1