Skip to content

Commit 8d131ca

Browse files
spokodevgithub-actions[bot]
authored andcommitted
Honor min/max-fraction-digits of 0
Closes internal-13697 GitOrigin-RevId: cc0557bf58bb25d9f3991a7876c6277d33527fbc
1 parent 2b75a5e commit 8d131ca

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

  • src/style-spec/expression/definitions
  • test/integration/expression-tests/number-format/max-fraction-digits-zero

src/style-spec/expression/definitions/number_format.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ export default class NumberFormat implements Expression {
6161
}
6262

6363
let minFractionDigits = null;
64-
if (options['min-fraction-digits']) {
64+
if (options['min-fraction-digits'] !== undefined) {
6565
minFractionDigits = context.parseObjectValue(options['min-fraction-digits'], 2, 'min-fraction-digits', NumberType);
6666
if (!minFractionDigits) return null;
6767
}
6868

6969
let maxFractionDigits = null;
70-
if (options['max-fraction-digits']) {
70+
if (options['max-fraction-digits'] !== undefined) {
7171
maxFractionDigits = context.parseObjectValue(options['max-fraction-digits'], 2, 'max-fraction-digits', NumberType);
7272
if (!maxFractionDigits) return null;
7373
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"expression": [
3+
"number-format",
4+
3.7,
5+
{
6+
"max-fraction-digits": ["get", "max"]
7+
}
8+
],
9+
"inputs": [
10+
[{}, {"properties": {"max": 0}}]
11+
],
12+
"expected": {
13+
"compiled": {
14+
"result": "success",
15+
"isFeatureConstant": false,
16+
"isZoomConstant": true,
17+
"type": "string"
18+
},
19+
"outputs": ["4"],
20+
"serialized": [
21+
"number-format",
22+
3.7,
23+
{
24+
"max-fraction-digits": ["number", ["get", "max"]]
25+
}
26+
]
27+
}
28+
}

0 commit comments

Comments
 (0)