blob: 3eb499b7ae9609c071c23c67f585d18c1d2f16e8 [file] [log] [blame]
// Copyright 2019 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of the engineering and scientific notations.
locale: [zh-TW]
features: [Intl.NumberFormat-unified]
---*/
const tests = [
[
0.000345,
"345E-6",
"3.45E-4",
],
[
0.345,
"345E-3",
"3.45E-1",
],
[
3.45,
"3.45E0",
"3.45E0",
],
[
34.5,
"34.5E0",
"3.45E1",
],
[
543,
"543E0",
"5.43E2",
],
[
5430,
"5.43E3",
"5.43E3",
],
[
543000,
"543E3",
"5.43E5",
],
[
543211.1,
"543.211E3",
"5.432E5",
],
[
-Infinity,
"-∞",
"-∞",
],
[
Infinity,
"∞",
"∞",
],
[
NaN,
"非數值",
"非數值",
],
];
for (const [number, engineering, scientific] of tests) {
const nfEngineering = (new Intl.NumberFormat("zh-TW", { notation: "engineering" }));
assert.sameValue(nfEngineering.format(number), engineering);
const nfScientific = (new Intl.NumberFormat("zh-TW", { notation: "scientific" }));
assert.sameValue(nfScientific.format(number), scientific);
}