Author: FabianLange
Date: 2010-03-23 17:56:48 +0100 (Tue, 23 Mar 2010)
New Revision: 28725
Modified:
branches/1.3/lib/i18n/sfNumberFormatInfo.class.php
branches/1.3/test/unit/helper/NumberHelperTest.php
branches/1.4/lib/i18n/sfNumberFormatInfo.class.php
branches/1.4/test/unit/helper/NumberHelperTest.php
Log:
[1.3, 1.4] fixed invalid number formatting occurring with currency formats
where no explicit negative format was defined (e.g for en_GB) (fixes #8433)
Modified: branches/1.3/lib/i18n/sfNumberFormatInfo.class.php
===================================================================
--- branches/1.3/lib/i18n/sfNumberFormatInfo.class.php 2010-03-23 16:40:52 UTC
(rev 28724)
+++ branches/1.3/lib/i18n/sfNumberFormatInfo.class.php 2010-03-23 16:56:48 UTC
(rev 28725)
@@ -277,24 +277,29 @@
$groupSize2 = false;
$decimalPoints = is_int($decimalPos) ? -1 : false;
- $info['negPref'] = $this->data['NumberElements'][6];
- $info['negPost'] = '';
-
$info['negative'] = $negative;
$info['positive'] = $pattern;
- // find the negative prefix and postfix
+ $posfix = $this->getPrePostfix($pattern);
+ $info['posPref'] = $posfix[0];
+ $info['posPost'] = $posfix[1];
+
if ($negative)
{
+ // find the negative prefix and postfix
$prefixPostfix = $this->getPrePostfix($negative);
$info['negPref'] = $prefixPostfix[0];
$info['negPost'] = $prefixPostfix[1];
}
+ else
+ {
+ // use the positive prefix and postfix and add the NegativeSign
+ //
http://www.unicode.org/reports/tr35/tr35-15.html#Number_Format_Patterns
+ // If there is no explicit negative subpattern, the negative subpattern
is the localized minus sign prefixed to the positive subpattern.
+ $info['negPref'] = $this->getNegativeSign().$info['posPref'];
+ $info['negPost'] = $info['posPost'];
+ }
- $posfix = $this->getPrePostfix($pattern);
- $info['posPref'] = $posfix[0];
- $info['posPost'] = $posfix[1];
-
if (is_int($groupPos1))
{
// get the second group
Modified: branches/1.3/test/unit/helper/NumberHelperTest.php
===================================================================
--- branches/1.3/test/unit/helper/NumberHelperTest.php 2010-03-23 16:40:52 UTC
(rev 28724)
+++ branches/1.3/test/unit/helper/NumberHelperTest.php 2010-03-23 16:56:48 UTC
(rev 28725)
@@ -27,6 +27,11 @@
$t->is(format_currency(1200000.101, 'USD', 'en'), '$1,200,000.10',
'format_currency() takes a number as its first argument');
$t->is(format_currency('1200000', 'USD', 'en'), '$1,200,000.00',
'format_currency() takes a number as its first argument');
+$t->is(format_currency(-1200000, 'USD', 'en'), '($1,200,000.00)',
'format_currency() takes a number as its first argument');
+$t->is(format_currency(-1200000, 'USD', 'en_GB'), '-$1,200,000.00',
'format_currency() takes a number as its first argument');
+//$t->is(format_currency(1200000, 'USD', 'de'), '1.200.000,00 $',
'format_currency() takes a number as its first argument');
+//$t->is(format_currency(-1200000, 'USD', 'de'), '-1.200.000,00 $',
'format_currency() takes a number as its first argument');
+
$t->is(format_currency('11.50999', 'USD', 'en'), '$11.50', 'format_currency()
takes a number as its first argument');
$t->is(format_currency('11.50999', 'EUR', 'fr'), '11,50 €', 'format_currency()
takes a number as its first argument');
$t->is(format_currency('11.9999464', 'EUR', 'fr'), '11,99 €',
'format_currency() takes a number as its first argument');
Modified: branches/1.4/lib/i18n/sfNumberFormatInfo.class.php
===================================================================
--- branches/1.4/lib/i18n/sfNumberFormatInfo.class.php 2010-03-23 16:40:52 UTC
(rev 28724)
+++ branches/1.4/lib/i18n/sfNumberFormatInfo.class.php 2010-03-23 16:56:48 UTC
(rev 28725)
@@ -277,24 +277,29 @@
$groupSize2 = false;
$decimalPoints = is_int($decimalPos) ? -1 : false;
- $info['negPref'] = $this->data['NumberElements'][6];
- $info['negPost'] = '';
-
$info['negative'] = $negative;
$info['positive'] = $pattern;
- // find the negative prefix and postfix
+ $posfix = $this->getPrePostfix($pattern);
+ $info['posPref'] = $posfix[0];
+ $info['posPost'] = $posfix[1];
+
if ($negative)
{
+ // find the negative prefix and postfix
$prefixPostfix = $this->getPrePostfix($negative);
$info['negPref'] = $prefixPostfix[0];
$info['negPost'] = $prefixPostfix[1];
}
+ else
+ {
+ // use the positive prefix and postfix and add the NegativeSign
+ //
http://www.unicode.org/reports/tr35/tr35-15.html#Number_Format_Patterns
+ // If there is no explicit negative subpattern, the negative subpattern
is the localized minus sign prefixed to the positive subpattern.
+ $info['negPref'] = $this->getNegativeSign().$info['posPref'];
+ $info['negPost'] = $info['posPost'];
+ }
- $posfix = $this->getPrePostfix($pattern);
- $info['posPref'] = $posfix[0];
- $info['posPost'] = $posfix[1];
-
if (is_int($groupPos1))
{
// get the second group
Modified: branches/1.4/test/unit/helper/NumberHelperTest.php
===================================================================
--- branches/1.4/test/unit/helper/NumberHelperTest.php 2010-03-23 16:40:52 UTC
(rev 28724)
+++ branches/1.4/test/unit/helper/NumberHelperTest.php 2010-03-23 16:56:48 UTC
(rev 28725)
@@ -27,6 +27,11 @@
$t->is(format_currency(1200000.101, 'USD', 'en'), '$1,200,000.10',
'format_currency() takes a number as its first argument');
$t->is(format_currency('1200000', 'USD', 'en'), '$1,200,000.00',
'format_currency() takes a number as its first argument');
+$t->is(format_currency(-1200000, 'USD', 'en'), '($1,200,000.00)',
'format_currency() takes a number as its first argument');
+$t->is(format_currency(-1200000, 'USD', 'en_GB'), '-$1,200,000.00',
'format_currency() takes a number as its first argument');
+//$t->is(format_currency(1200000, 'USD', 'de'), '1.200.000,00 $',
'format_currency() takes a number as its first argument');
+//$t->is(format_currency(-1200000, 'USD', 'de'), '-1.200.000,00 $',
'format_currency() takes a number as its first argument');
+
$t->is(format_currency('11.50999', 'USD', 'en'), '$11.50', 'format_currency()
takes a number as its first argument');
$t->is(format_currency('11.50999', 'EUR', 'fr'), '11,50 €', 'format_currency()
takes a number as its first argument');
$t->is(format_currency('11.9999464', 'EUR', 'fr'), '11,99 €',
'format_currency() takes a number as its first argument');
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.