jq: error: round/0 is not defined at <top-level>

Viewed 1575

round function in jq doesn't work.

$ jq '10.01 | round'
jq: error: round/0 is not defined at <top-level>, line 1:
10.01 | round        
jq: 1 compile error

$ jq --help
jq - commandline JSON processor [version 1.5-1-a5b5cbe]

What I need to do?

1 Answers

Seems like round is unavailable in your build. Either upgrade jq or implement round using floor:

def round: . + 0.5 | floor;

Usage example:

$ jq -n 'def round: . + 0.5 | floor; 10.01 | round'
10
Related