Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: test/intl/number-format/check-minimum-fraction-digits.js

Issue 1420883002: Fix user options for fractional digits in Intl.NumberFormatter (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/js/i18n.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/intl/number-format/check-minimum-fraction-digits.js
diff --git a/test/intl/number-format/check-minimum-fraction-digits.js b/test/intl/number-format/check-minimum-fraction-digits.js
index 57e65be55e22525322c457a45a4dfddc6ef373d1..b7d41dfca1a0305234e28171c0ad5d0e20367c93 100755
--- a/test/intl/number-format/check-minimum-fraction-digits.js
+++ b/test/intl/number-format/check-minimum-fraction-digits.js
@@ -2,8 +2,56 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Make sure minimumFractionDigits is honored
+// Make sure minimumFractionDigits and maximumFractionDigits are honored
-var nf = new Intl.NumberFormat("en-us",{ useGrouping: false, minimumFractionDigits: 4});
+var nf = new Intl.NumberFormat("en-us", { useGrouping: false, minimumFractionDigits: 4, maximumFractionDigits: 8});
assertEquals("12345.6789", nf.format(12345.6789));
+assertEquals("12345.678912", nf.format(12345.678912));
+assertEquals("12345.6700", nf.format(12345.67));
+assertEquals("12345.67891234", nf.format(12345.6789123421));
+
+nf = new Intl.NumberFormat("en-us", { useGrouping: false, minimumFractionDigits: 4, maximumFractionDigits: 8, style: 'percent'});
+
+assertEquals("12345.6789%", nf.format(123.456789));
+assertEquals("12345.678912%", nf.format(123.45678912));
+assertEquals("12345.6700%", nf.format(123.4567));
+assertEquals("12345.67891234%", nf.format(123.456789123421));
+
+nf = new Intl.NumberFormat('en', {minimumFractionDigits: 4, maximumFractionDigits: 8, style: 'currency', currency: 'USD'});
+
+assertEquals("$54,306.404797", nf.format(54306.4047970));
+assertEquals("$54,306.4000", nf.format(54306.4));
+assertEquals("$54,306.40000001", nf.format(54306.400000011));
+
+// Ensure that appropriate defaults exist when minimum and maximum are not specified
+
+nf = new Intl.NumberFormat("en-us", { useGrouping: false });
+
+assertEquals("12345.679", nf.format(12345.6789));
+assertEquals("12345.679", nf.format(12345.678912));
+assertEquals("12345.67", nf.format(12345.6700));
+assertEquals("12345", nf.format(12345));
+assertEquals("12345.679", nf.format(12345.6789123421));
+
+nf = new Intl.NumberFormat("en-us", { useGrouping: false, style: 'percent'});
+
+assertEquals("12346%", nf.format(123.456789));
+assertEquals("12346%", nf.format(123.45678912));
+assertEquals("12346%", nf.format(123.456700));
+assertEquals("12346%", nf.format(123.456789123421));
+assertEquals("12345%", nf.format(123.45));
+
+// For currency, the minimum or the maximum can be overwritten individually
+
+nf = new Intl.NumberFormat('en', {minimumFractionDigits: 0, style: 'currency', currency: 'USD'});
+
+assertEquals("$54,306.4", nf.format(54306.4047970));
+assertEquals("$54,306.4", nf.format(54306.4));
+assertEquals("$54,306", nf.format(54306));
+
+nf = new Intl.NumberFormat('en', {maximumFractionDigits: 3, style: 'currency', currency: 'USD'});
+
+assertEquals("$54,306.405", nf.format(54306.4047970));
+assertEquals("$54,306.40", nf.format(54306.4));
+assertEquals("$54,306.00", nf.format(54306));
« no previous file with comments | « src/js/i18n.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698