michael@0: // |reftest| skip-if(!this.hasOwnProperty("Intl")) michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Tests the format function with a diverse set of locales and options. michael@0: michael@0: var format; michael@0: michael@0: // Locale en-US; default options. michael@0: format = new Intl.NumberFormat("en-us"); michael@0: assertEq(format.format(0), "0"); michael@0: assertEq(format.format(-1), "-1"); michael@0: assertEq(format.format(123456789.123456789), "123,456,789.123"); michael@0: michael@0: // Locale en-US; currency USD. michael@0: // The US dollar uses two fractional digits, and negative values are commonly michael@0: // parenthesized. michael@0: format = new Intl.NumberFormat("en-us", {style: "currency", currency: "USD"}); michael@0: assertEq(format.format(0), "$0.00"); michael@0: assertEq(format.format(-1), "-$1.00"); michael@0: assertEq(format.format(123456789.123456789), "$123,456,789.12"); michael@0: michael@0: // Locale ja-JP; currency JPY. michael@0: // The Japanese yen has no subunit in real life. michael@0: format = new Intl.NumberFormat("ja-jp", {style: "currency", currency: "JPY"}); michael@0: assertEq(format.format(0), "¥0"); michael@0: assertEq(format.format(-1), "-¥1"); michael@0: assertEq(format.format(123456789.123456789), "¥123,456,789"); michael@0: michael@0: // Locale ar-JO; currency JOD. michael@0: // The Jordanian Dinar divides into 1000 fils. Jordan uses (real) Arabic digits. michael@0: format = new Intl.NumberFormat("ar-jo", {style: "currency", currency: "JOD"}); michael@0: assertEq(format.format(0), "د.أ.‏ ٠٫٠٠٠"); michael@0: assertEq(format.format(-1), "‏-د.أ.‏ ١٫٠٠٠"); michael@0: assertEq(format.format(123456789.123456789), "د.أ.‏ ١٢٣٬٤٥٦٬٧٨٩٫١٢٣"); michael@0: michael@0: // Locale th-TH; Thai digits, percent, two significant digits. michael@0: format = new Intl.NumberFormat("th-th-u-nu-thai", michael@0: {style: "percent", michael@0: minimumSignificantDigits: 2, michael@0: maximumSignificantDigits: 2}); michael@0: assertEq(format.format(0), "๐.๐%"); michael@0: assertEq(format.format(-0.01), "-๑.๐%"); michael@0: assertEq(format.format(1.10), "๑๑๐%"); michael@0: michael@0: reportCompare(0, 0, 'ok');