ZF-12181: Format of a negative number with precision 0 is ignored using locale of en_PY
Description
Using locale of es_PY and Zend_Currency, was trying to get a negative currency value using precision of 0. The positive values comes out good, the problem is when the value is a negative number. The negative currency ignores precision settings.
$locale = new Zend_Locale('es_PY');
$currency = new Zend_Currency(array('precision' => '0'), $locale);
// With value of -50000, it should show ₲ -50.000
$this->currency(-50000) // ₲ -50.000.00
// With value of 50000, it has no problem
$this->currency(50000) // ₲ 50.000
I was able to do a quick fix and get the result I wanted by commenting out a line in Zend_Locale_Format. It is not a fix, as I do not know whether the change I made breaks anything else. I am not a "pro" in programming, just 3-4 years of experience with it. Thought I'd report this as it was bugging me for a while.
This is the original code from Zend_Locale_Format starting on line 417:
if ($options['precision'] == '0') {
if (iconv_strrpos($format, '-') != 0) {
$format = iconv_substr($format, 0, $point);
. iconv_substr($format, iconv_strrpos($format, '#') + 2);
} else {
$format = iconv_substr($format, 0, $point);
}
} else {
$format = iconv_substr($format, 0, $point) . $symbols['decimal']
. iconv_substr($prec, 2);
}
The change I made was to comment out the concatenation on line 420.
if ($options['precision'] == '0') {
if (iconv_strrpos($format, '-') != 0) {
$format = iconv_substr($format, 0, $point);
// TODO: Make the quickfix a proper fix.
// The below portion was concatonated with the statement above
//. iconv_substr($format, iconv_strrpos($format, '#') + 2);
} else {
$format = iconv_substr($format, 0, $point);
}
} else {
$format = iconv_substr($format, 0, $point) . $symbols['decimal']
. iconv_substr($prec, 2);
}
Comments
Posted by Benno (benno) on 2012-10-03T08:34:13.000+0000
Same problem here, using «es_CL» as locale.