Skip to content

Commit 290986a

Browse files
andrew-colemanmattbaileyuk
authored andcommitted
allow leading zeros when casting string to number
1 parent 33d7940 commit 290986a

File tree

5 files changed

+25
-1
lines changed

5 files changed

+25
-1
lines changed

src/functions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ const functions = (() => {
11941194
if (typeof arg === 'number') {
11951195
// already a number
11961196
result = arg;
1197-
} else if (typeof arg === 'string' && /^-?(0|([1-9][0-9]*))(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(arg) && !isNaN(parseFloat(arg)) && isFinite(arg)) {
1197+
} else if (typeof arg === 'string' && /^-?[0-9]+(\.[0-9]+)?([Ee][-+]?[0-9]+)?$/.test(arg) && !isNaN(parseFloat(arg)) && isFinite(arg)) {
11981198
result = parseFloat(arg);
11991199
} else if (arg === true) {
12001200
// boolean true casts to 1
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$number('00')",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": 0
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$number('0123')",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": 123
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$number('-007')",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": -7
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$number('000.00123000')",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": 0.00123
6+
}

0 commit comments

Comments
 (0)