Bug #64534 [Opn->Nab]: Bad transfer variable from double to integer with specific number
| From: | johannes@php.net | Date: | Wed, 27 Mar 2013 15:51:27 +0000 |
| Subject: | Bug #64534 [Opn->Nab]: Bad transfer variable from double to integer with specific number | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-178149@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=64534&edit=1
ID: 64534
Updated by: johannes@php.net
Reported by: izolex4 at gmail dot com
Summary: Bad transfer variable from double to integer with
specific number
-Status: Open
+Status: Not a bug
Type: Bug
Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5.3Git-2013-03-27 (Git)
Block user comment: N
Private report: N
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://www.floating-point-gui.de/
Thank you for your interest in PHP.
.
Previous Comments:
------------------------------------------------------------------------
[2013-03-27 15:16:12] izolex4 at gmail dot com
Description:
------------
I have variable with type "double" with value 16.90 or 17.90 or 18.90 or 19.90.
Now multiply variable x 100 and now set type of variable to "integer" with
function "settype" and print this variable. Result will for example: 1989, even
that correct result is 1990. This make only, when original value is 16.90 or 17.90
or 18.90 or 19.90. If is original value another (for example 10.90 or 19.80),
result will
be correct (for example 1090 or 1980), but now is result incorrect for example
1989.
Test script:
---------------
<?php
$double = 19.90; // Only 16.90 or 17.90 or 18.90 or 19.90 will print bad result
$integer = $double*100; // Now is value 1990
settype($integer, 'integer'); // This change value to 1989 - bug
echo $integer;
Expected result:
----------------
Value of "integer" - 1990
Actual result:
--------------
Value of "integer" - 1989
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=64534&edit=1