From: stephane at it-asia dot com
Operating system: Windows 8 & Mint Maya
PHP version: 5.4.18
Package: *General Issues
Bug Type: Bug
Bug description:Cast gives different values in one way or the other
Description:
------------
I have different value when I cast a double to int and when I cast to
string before casting to int.
I understand 39.48 is difficult to store in base 2.
The problem is the cast algorythm is not the same if you cast a float to
int or if you cast a float to string, This involves huges mistakes in
accountancy software. Whatever the way you choose (float -> int or float ->
string -> int ) , you should have the same result at the end.
Please define the right way to process data in that case.
I have the same problem with almost every machines, Windows or Debian
based.
Thanks !
Test script:
---------------
$d = "39.48" * "100";
print("39.48 * 100 : ");
var_dump ($d);
$i = (int) $d;
print("<br />int: ");
var_dump ($i);
$s = (string) $d;
print("<br />string: ");
var_dump ($s);
$i = (int) $s;
print("<br />int: ");
var_dump ($i);
Expected result:
----------------
same value if you cast double => int and if you cast double => string =>
int
Actual result:
--------------
39.48 * 100 : double(3948)
int: int(3947)
string: string(4) "3948"
int: int(3948)
--
Edit bug report at https://bugs.php.net/bug.php?id=65485&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=65485&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=65485&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=65485&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=65485&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=65485&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=65485&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=65485&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=65485&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=65485&r=support
Expected behavior: https://bugs.php.net/fix.php?id=65485&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=65485&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=65485&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=65485&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65485&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=65485&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=65485&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=65485&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=65485&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=65485&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=65485&r=mysqlcfg