Bug #53775 [Com]: parseCurrency returns 0 instead of false
| From: | _coola_ at arcor dot de | Date: | Wed, 26 Jan 2011 11:28:07 +0000 |
| Subject: | Bug #53775 [Com]: parseCurrency returns 0 instead of false | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-158197@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53775&edit=1
ID: 53775
Comment by: _coola_ at arcor dot de
Reported by: _coola_ at arcor dot de
Summary: parseCurrency returns 0 instead of false
Status: Bogus
Type: Bug
Package: I18N and L10N related
Operating System: win xp
PHP Version: 5.3SVN-2011-01-18 (SVN)
Block user comment: N
Private report: N
New Comment:
Correct! That´s the problem. Thank you. :)
Previous Comments:
------------------------------------------------------------------------
[2011-01-25 16:41:12] garioch2 at googlemail dot com
I read the bug report and your reply as well.
According to the respective manual page
"returns the parsed value or FALSE on error" -> I would expect to get
FALSE when trying to parse 'aaa' into any available currency and locale
(And the one who wrote the bug report too) ^^
Instead it appears that the parseCurrency method just uses the locale to
transform the float number it expects in the String-parameter
And then simply uses float_val() to convert the string to a real float
value.
Thus we get 0 (zero) for trying to parse 'aaa'.
But this makes it hard to differentiate between
a real Zero and a Zero occuring coz of wrong input-data. And I think the
FALSE would really help in the latter case (as in various
string-functions like strpos and so on)
thanks for your time!
------------------------------------------------------------------------
[2011-01-19 17:24:43] _coola_ at arcor dot de
1st parameter has to be a string
http://php.net/manual/en/numberformatter.parsecurrency.php
------------------------------------------------------------------------
[2011-01-18 14:01:59] iliaa@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
The parseCurrency() expects the 1st parameter to be a float, when given
a string
PHP automatically casts it to float resulting in 0.
------------------------------------------------------------------------
[2011-01-18 09:56:58] _coola_ at arcor dot de
Description:
------------
Hi! :)
I think i have found a bug in NumberFormatter.
parseCurrency() returns 0 instead of false in the following test
script.
Same Problem with parse().
Test script:
---------------
$fmt=new NumberFormatter('de_DE',NumberFormatter::CURRENCY);
$result=$fmt->parseCurrency('aaa',$currency);
//$result=$fmt->parse('aaa');
// results:
var_dump($result); // float(0)
var_dump($currency); // string(0) ""
// no errors!!
var_dump($fmt->getErrorCode()); // int(0)
var_dump($fmt->getErrorMessage()); // string(12)
"U_ZERO_ERROR"
var_dump(intl_is_failure($fmt->getErrorCode())); // bool(false)
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53775&edit=1