aboutsummaryrefslogtreecommitdiff
path: root/env/.local/bin/scripts/math
blob: 26d48541d43cf5e7da7290fd58a1e9e0b7057c9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/bin/bash
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"