js/src/tests/Intl/NumberFormat/format.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:936c44114bd8
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 // Tests the format function with a diverse set of locales and options.
7
8 var format;
9
10 // Locale en-US; default options.
11 format = new Intl.NumberFormat("en-us");
12 assertEq(format.format(0), "0");
13 assertEq(format.format(-1), "-1");
14 assertEq(format.format(123456789.123456789), "123,456,789.123");
15
16 // Locale en-US; currency USD.
17 // The US dollar uses two fractional digits, and negative values are commonly
18 // parenthesized.
19 format = new Intl.NumberFormat("en-us", {style: "currency", currency: "USD"});
20 assertEq(format.format(0), "$0.00");
21 assertEq(format.format(-1), "-$1.00");
22 assertEq(format.format(123456789.123456789), "$123,456,789.12");
23
24 // Locale ja-JP; currency JPY.
25 // The Japanese yen has no subunit in real life.
26 format = new Intl.NumberFormat("ja-jp", {style: "currency", currency: "JPY"});
27 assertEq(format.format(0), "¥0");
28 assertEq(format.format(-1), "-¥1");
29 assertEq(format.format(123456789.123456789), "¥123,456,789");
30
31 // Locale ar-JO; currency JOD.
32 // The Jordanian Dinar divides into 1000 fils. Jordan uses (real) Arabic digits.
33 format = new Intl.NumberFormat("ar-jo", {style: "currency", currency: "JOD"});
34 assertEq(format.format(0), "د.أ.‏ ٠٫٠٠٠");
35 assertEq(format.format(-1), "‏-د.أ.‏ ١٫٠٠٠");
36 assertEq(format.format(123456789.123456789), "د.أ.‏ ١٢٣٬٤٥٦٬٧٨٩٫١٢٣");
37
38 // Locale th-TH; Thai digits, percent, two significant digits.
39 format = new Intl.NumberFormat("th-th-u-nu-thai",
40 {style: "percent",
41 minimumSignificantDigits: 2,
42 maximumSignificantDigits: 2});
43 assertEq(format.format(0), "๐.๐%");
44 assertEq(format.format(-0.01), "-๑.๐%");
45 assertEq(format.format(1.10), "๑๑๐%");
46
47 reportCompare(0, 0, 'ok');

mercurial