Details
-
Type:
Improvement
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.5.0RC1
-
Fix Version/s: 1.5.0
-
Component/s: Zend_Locale
-
Labels:None
Description
The core of the problem is locale dependent numbers processing behavior, especially strings <-> numbers conversion.
float -> string conversion uses zend_spprintf() function, which actually uses xbuf_format_converter() function. xbuf_format_converter() uses decimal point provided by current locale.
string -> float conversion uses zend_strtod() function which has hardcoded decimal point character ('.')
So float -> string -> float conversion may be not reversible operation for locales which don't use '.' as decimal point (e.g. fr_FR locale uses ',');
setlocale(LC_ALL,'fr_FR'); var_dump((float)26.25); // output: float(26,25) setlocale(LC_ALL,'fr_FR'); var_dump((string)(float)26.25); // output: string(5) "26,25" setlocale(LC_ALL,'fr_FR'); var_dump((float)(string)(float)26.25); // output: float(26)
I am not sure it's a bug, since that exactly corresponds to the behavior described in the PHP manual (http://www.php.net/manual/en/language.types.type-juggling.php#language.types.typecasting)
That affects our implementation of Zend_Locale_Math_PhpMath methods.
Another problem is bcmath extension behavior. bcmath functions take strings as arguments. Conversion to the strings is performed automatically. But! bcmath functions operate with '.' as decimal point. If it gets another symbol it treats number as zero:
setlocale(LC_ALL,'fr_FR'); var_dump(bcadd(1, '2.25', 2)); // output: string(4) "3.25" setlocale(LC_ALL,'fr_FR'); var_dump(bcadd(1, '2,25', 2)); // output: string(4) "1.00" setlocale(LC_ALL,'fr_FR'); var_dump(bcadd(1, 2.25, 2)); // output: string(4) "1.00"
So we have to provide input for math functions as non-localized strings with numbers.
With the change from
ZF-2813and the last changeset 8584 the problem should be prevented.Now all inputs are converted to string and only string is returned.
ZF-2813and the last changeset 8584 the problem should be prevented. Now all inputs are converted to string and only string is returned.