aboutsummaryrefslogtreecommitdiff
path: root/env/.local/bin/scripts/math
blob: 9c9b3053239b41ab3a50e7f908ac59ba5c374e2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/sh
expression=$1
precision=$2

if [ "$precision" == "" ]; then
    precision=1;
fi;

# Perform arithmetic operation using awk
result=$(awk "BEGIN {printf \"%.${precision}f\n\", $expression}" | sed 's/\.0$//')

# Print the result
echo "$result"