Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 0.8.0
-
Fix Version/s: 1.0.3
-
Component/s: Zend_Locale
-
Labels:None
Description
I've had some troubles using Zend_Locale_Format ::toFloat() along with setlocale().
Here is a sample code to illustrate the issue :
require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Locale');
// setlocale(LC_ALL, 'fr_FR@euro');
$locale_fr = new Zend_Locale('fr_FR');
$locale_en = new Zend_Locale('en_US');
$params_fr = array('precision' => 2, 'locale' => $locale_fr);
$params_en = array('precision' => 2, 'locale' => $locale_en);
$myFloat = 1234.5;
$test1 = Zend_Locale_Format::toFloat($myFloat, $params_fr);
$test2 = Zend_Locale_Format::toFloat($myFloat, $params_en);
var_dump($test1);
var_dump($test2);
The problem comes from the setlocale() call : if it is not present, everything goes fine but when I set PHP's locale to French, I can't get toFloat() to work.
Output without setlocale() :
string(9) "1 234,50" string(8) "1,234.50"
Output with setlocale() :
string(4) "0,00" string(4) "0.00"
The server I work on is a Linux box (Debian stable), and AFAIK, the standard locale is 'C'. I'm using PHP version 5.2.1 with the BCmath extension enabled. Regarding the framework, I had this problem while I was using the 0.8.0 version and it is still present in the 3912 SVN version.
Last thing, I quote a short part of Thomas' last answer on the mailing list :
So toNumberFormat does not have to parse for the decimal point, because the input is not a string but a integer/float value.
Are you 100% positive about that ? I'm saying that because when I see a piece of code like the following :
// get number parts if (iconv_strpos($value, '.') !== false) {
in toNumberFormat(), my first guess would be that you are actually looking for the decimal separator in the input value.
This seems to be confirmed by a short trace I ran on this part of code :
--- Format.php.orig 2007-03-14 09:48:00.000000000 +0100
+++ Format.php 2007-03-14 10:37:43.000000000 +0100
@@ -385,10 +385,12 @@
$precstr = $precstr . str_pad("0", ($options['precision'] - iconv_strlen($precstr)), "0");
}
}
+ die('strpos true : ' . $precstr);
} else {
if ($options['precision'] > 0) {
$precstr = str_pad("0", ($options['precision']), "0");
}
+ die('strpos false : ' . $precstr);
}
if ($options['precision'] === null) {
if (isset($precstr)) {
Output without setlocale() :
strpos true : 50
Output with setlocale() :
strpos false : 00
Behaviour of this part of code is different whether the locale is set to French or not.
Hopefully there's enough information in this description, if not just let me know ![]()
Issue Links
| This issue depends on: | ||||
| ZF-1061 | Use of PHP's setlocale() may break functionality in Zend_Locale_Format |
|
|
|
I am sure.
Please try this code so we can see if iconv_strpos works on your system:
I see 2 possible problems:
1.) setLocale has false settings on your OS.
2.) BCMath is set to precision 0 within php.ini.