Skip to content

Commit 6092352

Browse files
authored
Precision fix for $string function (#762)
Signed-off-by: Ivan Majeru <[email protected]>
1 parent 2bb2589 commit 6092352

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/functions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ const functions = (() => {
131131
arg = arg[0];
132132
}
133133
str = JSON.stringify(arg, function (key, val) {
134-
return (typeof val !== 'undefined' && val !== null && val.toPrecision && isNumeric(val)) ? Number(val.toPrecision(15)) :
135-
(val && isFunction(val)) ? '' : val;
134+
if (typeof val !== 'undefined' && val !== null && isNumeric(val)) {
135+
return val.toPrecision && !Number.isInteger(val) ? Number(val.toPrecision(15)) : val;
136+
}
137+
return val && isFunction(val) ? '' : val;
136138
}, space);
137139
}
138140
return str;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$formatBase(big_id)",
3+
"data": { "big_id": 5890840712243076 },
4+
"bindings": {},
5+
"result": "5890840712243076"
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$string(big_id)",
3+
"data": { "big_id": 5890840712243076 },
4+
"bindings": {},
5+
"result": "5890840712243076"
6+
}

0 commit comments

Comments
 (0)