aboutsummaryrefslogtreecommitdiff
path: root/env/.local/bin/scripts/math
diff options
context:
space:
mode:
Diffstat (limited to 'env/.local/bin/scripts/math')
-rwxr-xr-xenv/.local/bin/scripts/math13
1 files changed, 13 insertions, 0 deletions
diff --git a/env/.local/bin/scripts/math b/env/.local/bin/scripts/math
new file mode 100755
index 0000000..26d4854
--- /dev/null
+++ b/env/.local/bin/scripts/math
@@ -0,0 +1,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"