[ak] Support percent/permille formats with positive and negative variations
BUG=
R=efortuna@google.com
Review URL: https://codereview.chromium.org//607153002
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/intl@40733 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3e3e69c..c08f649 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,9 @@
+## 0.11.9
+ * Fix bug with per-mille parsing (only divided by 100, not 1000)
+
+ * Support percent and per-mille formats with both positive and negative
+ variations. Previously would throw an exception for too many modifiers.
+
## 0.11.8
* Support NumberFormats with two different grouping sizes, e.g.
diff --git a/lib/src/intl/number_format.dart b/lib/src/intl/number_format.dart
index e43b471..377db7d 100644
--- a/lib/src/intl/number_format.dart
+++ b/lib/src/intl/number_format.dart
@@ -495,11 +495,11 @@
symbols.EXP_SYMBOL: () => 'E',
symbols.GROUP_SEP: handleSpace,
symbols.PERCENT: () {
- scale = 100;
+ scale = _NumberFormatParser._PERCENT_SCALE;
return '';
},
symbols.PERMILL: () {
- scale = 1000;
+ scale = _NumberFormatParser._PER_MILLE_SCALE;
return '';
},
' ' : handleSpace,
@@ -676,7 +676,9 @@
static const _PATTERN_DECIMAL_SEPARATOR = '.';
static const _PATTERN_CURRENCY_SIGN = '\u00A4';
static const _PATTERN_PER_MILLE = '\u2030';
+ static const _PER_MILLE_SCALE = 1000;
static const _PATTERN_PERCENT = '%';
+ static const _PERCENT_SCALE = 100;
static const _PATTERN_EXPONENT = 'E';
static const _PATTERN_PLUS = '+';
@@ -778,17 +780,18 @@
affix.write(currencyName);
break;
case _PATTERN_PERCENT:
- if (format._multiplier != 1) {
+ if (format._multiplier != 1 && format._multiplier != _PERCENT_SCALE) {
throw new FormatException('Too many percent/permill');
}
- format._multiplier = 100;
+ format._multiplier = _PERCENT_SCALE;
affix.write(symbols.PERCENT);
break;
case _PATTERN_PER_MILLE:
- if (format._multiplier != 1) {
+ if (format._multiplier != 1 &&
+ format._multiplier != _PER_MILLE_SCALE) {
throw new FormatException('Too many percent/permill');
}
- format._multiplier = 1000;
+ format._multiplier = _PER_MILLE_SCALE;
affix.write(symbols.PERMILL);
break;
default:
diff --git a/pubspec.yaml b/pubspec.yaml
index dad9a65..b87c445 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: intl
-version: 0.11.8
+version: 0.11.9
author: Dart Team <misc@dartlang.org>
description: Contains code to deal with internationalized/localized messages, date and number formatting and parsing, bi-directional text, and other internationalization issues.
homepage: https://www.dartlang.org
diff --git a/test/number_format_test.dart b/test/number_format_test.dart
index 83d53d8..1ff898b 100644
--- a/test/number_format_test.dart
+++ b/test/number_format_test.dart
@@ -187,6 +187,12 @@
expect(readBack, amount);
});
+ test("Delta percent format", () {
+ var f = new NumberFormat("+#,##0%;-#,##0%");
+ expect(f.format(-0.07), "-7%");
+ expect(f.format(0.12), "+12%");
+ });
+
test('Unparseable', () {
var format = new NumberFormat.currencyPattern();
expect(() => format.parse("abcdefg"), throwsFormatException);