aboutsummaryrefslogtreecommitdiff
path: root/env/.local/bin/scripts/math
blob: 2236da442457f77a69f032ad229bc4376aa6b8ff (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"