Bug #67676 [Opn->Nab]: (int) return wrong number
| From: | requinix@php.net | Date: | Thu, 24 Jul 2014 16:33:01 +0000 |
| Subject: | Bug #67676 [Opn->Nab]: (int) return wrong number | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-186803@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67676&edit=1
ID: 67676
Updated by: requinix@php.net
Reported by: andreiotetea at yahoo dot com
Summary: (int) return wrong number
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Linux, Windows, all
PHP Version: Irrelevant
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:
------------------------------------------------------------------------
[2014-07-24 12:57:00] andreiotetea at yahoo dot com
Description:
------------
this is a general BUG, no matter of system used or php version..on all is same
tested here too: http://sandbox.onlinephpfunctions.com/
(int) is returning wrong number without trim.
Test script:
---------------
<?php
$number = 10.03;
$mfactor = pow(10,2);
echo (int)($number * $mfactor); // 1002 - wrong
echo (int)trim($number * $mfactor); // 1003 - good
?>
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67676&edit=1