php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31889 Strings of the format -.55 are not converted to numbers correctly
Submitted: 2005-02-08 22:49 UTC Modified: 2005-02-09 01:11 UTC
From: justinpatrin@php.net Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.3.10 OS: Linux
Private report: No CVE-ID: None
 [2005-02-08 22:49 UTC] justinpatrin@php.net
Description:
------------
A string which holds a number which is less than 0 but greater than -1 and does not have a leading 0, is not converted to a number correctly, it comes back as 0.

Reproduce code:
---------------
$str = '-.55';
echo $str."\n".(int)$str;

Expected result:
----------------
-.55
-.55

Actual result:
--------------
-.55
0

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-02-08 23:35 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

read your code again
 [2005-02-09 00:04 UTC] justinpatrin@php.net
Ok, you're right, my code is broken, I should have (float) instead of (int). Stupid me. And that fixes that code. 

However, consider this code:

$str = '-.55';
$num = $num2 = 0;
$num += $str;
$num2 += (float)$str;
echo $str."\n".(float)$str."\n".$num."\n".$num2."\n";

This outputs:
-.55
-0.55
0
-0.55

But should output:
-.55
-0.55
-0.55
-0.55


The snapshot fixes this, thanks.
 [2005-02-09 00:07 UTC] tony2001@php.net
Fixed in snapshot -> closed.
 [2005-02-09 01:11 UTC] justinpatrin@php.net
Just for information's sake, this bug came up because Oracle (at least the version we're using) returns NUMBER columns in this range without a leading 0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Oct 09 03:01:28 2024 UTC