Bug #76105 [NEW]: String to Number conversions
From: mail at fsax dot ch
Operating system: all
PHP version: Irrelevant
Package: *General Issues
Bug Type: Bug
Bug description:String to Number conversions
Description:
------------
Some String to Number conversions create unexpected results that can
lead to bad miscalculations.
On the php.net docs i found a warning:
"Never cast an unknown fraction to integer, as this can sometimes lead
to unexpected results."
but i think the root of my issue manifests while the float is beeing
cast, since the floor() has the same result.
Test script:
---------------
echo ("9312.80" *100)."<br>\n";
echo (((float) "9312.80") *100)."<br>\n";
echo (int) ("9312.80" *100)."<br>\n";
echo floor( "9312.80" *100);
Expected result:
----------------
237280<br>
237280<br>
237280<br>
237280
Actual result:
--------------
237280<br>
237280<br>
931279<br>
931279
--
Edit bug report at https://bugs.php.net/bug.php?id=76105&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76105&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76105&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76105&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76105&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76105&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76105&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76105&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76105&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76105&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76105&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76105&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76105&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76105&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76105&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76105&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76105&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76105&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76105&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76105&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76105&r=mysqlcfg
Thread (2 messages)
- mail at fsax dot ch