#47304 [Opn]: typecast of numeric string to float produces strange result
ID: 47304
User updated by: lennartvdd at mailordersolutions dot nl
Reported By: lennartvdd at mailordersolutions dot nl
Status: Open
Bug Type: Scripting Engine problem
Operating System: Server 2003 for SBS SP2 - IIS
PHP Version: 5.2.8
New Comment:
For some strange reason the problem is reoccurring again with version
5.2.9-dev!
Reproduce code:
---------------
echo "PHP version: " . PHP_VERSION . "\n";
$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);
Actual result:
--------------
PHP version: 5.2.9-dev
float(-38.:)
float(38.:)
float(16.:)
float(-16.:)
float(-38.:)
float(38.:)
float(16.:)
float(-16.:)
Previous Comments:
------------------------------------------------------------------------
[2009-02-05 09:12:01] lennartvdd at mailordersolutions dot nl
I installed the latest version like you recommended (PHP version:
5.2.9-dev (win32 x86 VC6)). That fixed it.
------------------------------------------------------------------------
[2009-02-04 22:22:23] jani@php.net
Forgot this, output on my linux server using PHP 5.2.8:
float(-39)
float(39)
float(17)
float(-17)
float(-39)
float(39)
float(17)
float(-17)
------------------------------------------------------------------------
[2009-02-04 22:21:37] jani@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5.2-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2009-02-04 12:41:54] lennartvdd at mailordersolutions dot nl
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 this bug report at http://bugs.php.net/?id=47304&edit=1
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