Skip to content

Commit 09dba37

Browse files
andrew-colemanmattbaileyuk
authored andcommitted
$pad function to truncate fractional part of numeric argument
Signed-off-by: Andrew Coleman <[email protected]>
1 parent 2dd49c6 commit 09dba37

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/functions.js

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ const functions = (() => {
293293
}
294294

295295
var result;
296+
width = Math.trunc(width);
296297
var padLength = Math.abs(width) - length(str);
297298
if (padLength > 0) {
298299
var padding = (new Array(padLength + 1)).join(char);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$pad('foo', 5.7, ' ')",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": "foo "
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"expr": "$pad('foo', -5.7, ' ')",
3+
"dataset": null,
4+
"bindings": {},
5+
"result": " foo"
6+
}

0 commit comments

Comments
 (0)