1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// |reftest| skip-if(!this.hasOwnProperty("Intl")||release_or_beta)
// "stripIfInteger" with fractional digits.
{
let nf1 = new Intl.NumberFormat("en", {
minimumFractionDigits: 2,
});
let nf2 = new Intl.NumberFormat("en", {
minimumFractionDigits: 2,
trailingZeroDisplay: "auto",
});
let nf3 = new Intl.NumberFormat("en", {
minimumFractionDigits: 2,
trailingZeroDisplay: "stripIfInteger",
});
assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto");
assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto");
assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger");
assertEq(nf1.format(123), "123.00");
assertEq(nf2.format(123), "123.00");
assertEq(nf3.format(123), "123");
}
// "stripIfInteger" with significand digits.
{
let nf1 = new Intl.NumberFormat("en", {
minimumSignificantDigits: 2,
});
let nf2 = new Intl.NumberFormat("en", {
minimumSignificantDigits: 2,
trailingZeroDisplay: "auto",
});
let nf3 = new Intl.NumberFormat("en", {
minimumSignificantDigits: 2,
trailingZeroDisplay: "stripIfInteger",
});
assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto");
assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto");
assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger");
assertEq(nf1.format(1), "1.0");
assertEq(nf2.format(1), "1.0");
assertEq(nf3.format(1), "1");
}
// "stripIfInteger" with rounding increment.
{
let nf1 = new Intl.NumberFormat("en", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
roundingIncrement: 5,
});
let nf2 = new Intl.NumberFormat("en", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
roundingIncrement: 5,
trailingZeroDisplay: "auto",
});
let nf3 = new Intl.NumberFormat("en", {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
roundingIncrement: 5,
trailingZeroDisplay: "stripIfInteger",
});
assertEq(nf1.resolvedOptions().trailingZeroDisplay, "auto");
assertEq(nf2.resolvedOptions().trailingZeroDisplay, "auto");
assertEq(nf3.resolvedOptions().trailingZeroDisplay, "stripIfInteger");
// NB: Tests 1.975 twice b/c of <https://unicode-org.atlassian.net/browse/ICU-21674>.
assertEq(nf1.format(1.975), "2.00");
assertEq(nf1.format(1.97), "1.95");
assertEq(nf1.format(1.975), "2.00");
assertEq(nf2.format(1.975), "2.00");
assertEq(nf2.format(1.97), "1.95");
assertEq(nf2.format(1.975), "2.00");
assertEq(nf3.format(1.975), "2");
assertEq(nf3.format(1.97), "1.95");
assertEq(nf3.format(1.975), "2");
}
// Invalid values.
for (let trailingZeroDisplay of ["", "true", true, "none", "yes", "no"]){
assertThrowsInstanceOf(() => new Intl.NumberFormat("en", {trailingZeroDisplay}), RangeError);
}
if (typeof reportCompare === "function")
reportCompare(true, true);
|