1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/Intl/NumberFormat/format.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +// |reftest| skip-if(!this.hasOwnProperty("Intl")) 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +// Tests the format function with a diverse set of locales and options. 1.10 + 1.11 +var format; 1.12 + 1.13 +// Locale en-US; default options. 1.14 +format = new Intl.NumberFormat("en-us"); 1.15 +assertEq(format.format(0), "0"); 1.16 +assertEq(format.format(-1), "-1"); 1.17 +assertEq(format.format(123456789.123456789), "123,456,789.123"); 1.18 + 1.19 +// Locale en-US; currency USD. 1.20 +// The US dollar uses two fractional digits, and negative values are commonly 1.21 +// parenthesized. 1.22 +format = new Intl.NumberFormat("en-us", {style: "currency", currency: "USD"}); 1.23 +assertEq(format.format(0), "$0.00"); 1.24 +assertEq(format.format(-1), "-$1.00"); 1.25 +assertEq(format.format(123456789.123456789), "$123,456,789.12"); 1.26 + 1.27 +// Locale ja-JP; currency JPY. 1.28 +// The Japanese yen has no subunit in real life. 1.29 +format = new Intl.NumberFormat("ja-jp", {style: "currency", currency: "JPY"}); 1.30 +assertEq(format.format(0), "¥0"); 1.31 +assertEq(format.format(-1), "-¥1"); 1.32 +assertEq(format.format(123456789.123456789), "¥123,456,789"); 1.33 + 1.34 +// Locale ar-JO; currency JOD. 1.35 +// The Jordanian Dinar divides into 1000 fils. Jordan uses (real) Arabic digits. 1.36 +format = new Intl.NumberFormat("ar-jo", {style: "currency", currency: "JOD"}); 1.37 +assertEq(format.format(0), "د.أ. ٠٫٠٠٠"); 1.38 +assertEq(format.format(-1), "-د.أ. ١٫٠٠٠"); 1.39 +assertEq(format.format(123456789.123456789), "د.أ. ١٢٣٬٤٥٦٬٧٨٩٫١٢٣"); 1.40 + 1.41 +// Locale th-TH; Thai digits, percent, two significant digits. 1.42 +format = new Intl.NumberFormat("th-th-u-nu-thai", 1.43 + {style: "percent", 1.44 + minimumSignificantDigits: 2, 1.45 + maximumSignificantDigits: 2}); 1.46 +assertEq(format.format(0), "๐.๐%"); 1.47 +assertEq(format.format(-0.01), "-๑.๐%"); 1.48 +assertEq(format.format(1.10), "๑๑๐%"); 1.49 + 1.50 +reportCompare(0, 0, 'ok');