Skip to content

Commit

Permalink
$pad function to truncate fractional part of numeric argument
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Coleman <[email protected]>
  • Loading branch information
andrew-coleman authored and mattbaileyuk committed Jan 14, 2025
1 parent 2dd49c6 commit 09dba37
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const functions = (() => {
}

var result;
width = Math.trunc(width);
var padLength = Math.abs(width) - length(str);
if (padLength > 0) {
var padding = (new Array(padLength + 1)).join(char);
Expand Down
6 changes: 6 additions & 0 deletions test/test-suite/groups/function-pad/case011.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"expr": "$pad('foo', 5.7, ' ')",
"dataset": null,
"bindings": {},
"result": "foo "
}
6 changes: 6 additions & 0 deletions test/test-suite/groups/function-pad/case012.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"expr": "$pad('foo', -5.7, ' ')",
"dataset": null,
"bindings": {},
"result": " foo"
}

0 comments on commit 09dba37

Please sign in to comment.