#47304 [NEW]: typecast of numeric string to float produces strange result
From: lennartvdd at mailordersolutions dot nl
Operating system: Server 2003 for SBS SP2 - IIS
PHP version: 5.2.8
PHP Bug Type: Variables related
Bug description: typecast of numeric string to float produces strange result
Description:
------------
Typecasting or converting some numeric strings variables to a float value
does not work as expected.
Reproduce code:
---------------
$var = (float)"-39.000";
var_dump($var);
$var = (float)"39.000";
var_dump($var);
$var = (float)"17.000";
var_dump($var);
$var = (float)"-17.000";
var_dump($var);
$var = "-39.000" + 0;
var_dump($var);
$var = "39.000" + 0;
var_dump($var);
$var = "17.000" + 0;
var_dump($var);
$var = "-17.000" + 0;
var_dump($var);
Expected result:
----------------
float(-39)
float(39)
float(17)
float(-17)
float(-39)
float(39)
float(17)
float(-17)
Actual result:
--------------
float(-38.:)
float(38.:)
float(16.:)
float(-16.:)
float(-38.:)
float(38.:)
float(16.:)
float(-16.:)
--
Edit bug report at http://bugs.php.net/?id=47304&edit=1
--
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47304&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47304&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47304&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=47304&r=fixedcvs
Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47304&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=47304&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=47304&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=47304&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=47304&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=47304&r=support
Expected behavior: http://bugs.php.net/fix.php?id=47304&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=47304&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=47304&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=47304&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47304&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=47304&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=47304&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=47304&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=47304&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=47304&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=47304&r=mysqlcfg
Thread (35 messages)
- lennartvdd at mailordersolutions dot nl
- jani@php.net#47304 [Opn->Fbk]: typecast of numeric string to float produces strange result
- jani@php.net#47304 [Fbk]: typecast of numeric string to float produces strange result
- lennartvdd at mailordersolutions dot nl#47304 [Fbk->Opn]: typecast of numeric string to float produces strange result
- lennartvdd at mailordersolutions dot nl#47304 [Opn]: typecast of numeric string to float produces strange result
- jani@php.net#47304 [Opn->Fbk]: typecast of numeric string to float produces strange result
- lennartvdd at mailordersolutions dot nl#47304 [Fbk->Opn]: typecast of numeric string to float produces strange result
- jani@php.net#47304 [Opn->Fbk]: typecast of numeric string to float produces strange result
- pajoye@php.net#47304 [NoF->Fbk]: typecast of numeric string to float produces strange result
- pajoye@php.net#47304 [Fbk]: typecast of numeric string to float produces strange result
- pajoye@php.net#47304 [Fbk]: typecast of numeric string to float produces strange result
- codeslinger at compsalot dot com#47304 [Com]: typecast of numeric string to float produces strange result
- egorich at junik dot lv#47304 [Com]: typecast of numeric string to float produces strange result
- egorich at junik dot lv#47304 [Com]: typecast of numeric string to float produces strange result
- pajoye@php.net#47304 [NoF->Asn]: typecast of numeric string to float produces strange result
- egorich at junik dot lv#47304 [Com]: typecast of numeric string to float produces strange result
- ang dot chin dot han at gmail dot com#47304 [Com]: typecast of numeric string to float produces strange result
- ciudadsatan at hotmail dot com#47304 [Com]: typecast of numeric string to float produces strange result
- egorich at junik dot lv#47304 [Com]: typecast of numeric string to float produces strange result
- p dot klein at letsmakesense dot de#47304 [Com]: typecast of numeric string to float produces strange result
- xiaobo dot bob at gmail dot comBug #47304 [Com]: typecast of numeric string to float produces strange result
- pajoye@php.netBug #47304 [Asn->Fbk]: typecast of numeric string to float produces strange result
- xiaobo dot bob at gmail dot comBug #47304 [Com]: typecast of numeric string to float produces strange result
- pajoye@php.netBug #47304 [Fbk]: typecast of numeric string to float produces strange result
- xiaobo dot bob at gmail dot comBug #47304 [Com]: typecast of numeric string to float produces strange result
- xiaobo dot bob at gmail dot comBug #47304 [Com]: typecast of numeric string to float produces strange result
- xiaobo dot bob at gmail dot comBug #47304 [Com]: typecast of numeric string to float produces strange result
- ola dot andersson at liko dot seBug #47304 [Com]: typecast of numeric string to float produces strange result
- ola dot andersson at liko dot seBug #47304 [Com]: typecast of numeric string to float produces strange result
- pajoye@php.netBug #47304 [Fbk]: typecast of numeric string to float produces strange result
- ola dot andersson at liko dot seBug #47304 [Com]: typecast of numeric string to float produces strange result
- lennart dot vandendool at fonq dot nlBug #47304 [Fbk->Asn]: typecast of numeric string to float produces strange result
- lennart dot vandendool at fonq dot nlBug #47304 [Asn]: typecast of numeric string to float produces strange result
- michael dot fellinger at multitec-sono dot atBug #47304 [Com]: typecast of numeric string to float produces strange result
- pajoye@php.netBug #47304 [Asn->Wfx]: typecast of numeric string to float produces strange result