From 44afe2cdcd9ef3435a2c0c3a9d35b36db24afbe4 Mon Sep 17 00:00:00 2001 From: olli Date: Tue, 31 Oct 2023 17:29:38 +0100 Subject: [PATCH] =?UTF-8?q?gaboshlib/g=5Fnum=5Fis=5Fapprox.sh=20hinzugef?= =?UTF-8?q?=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gaboshlib/g_num_is_approx.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 gaboshlib/g_num_is_approx.sh diff --git a/gaboshlib/g_num_is_approx.sh b/gaboshlib/g_num_is_approx.sh new file mode 100644 index 0000000..3b5ebf7 --- /dev/null +++ b/gaboshlib/g_num_is_approx.sh @@ -0,0 +1,17 @@ +function g_num_is_approx { + + # check if $1 is in percentage range ($3 and $4) to $2 + local f_num=$1 + local f_base=$2 + local f_percentage_up=$3 + local f_percentage_down=$4 + + # Check for valid decimal number + + g_num_valid_number "${f_num}" "${f_base}" "${f_percentage_up}" "${f_percentage_down}" || return 1 + + local f_from=$(echo "${f_base} - (${f_base} / 100 * ${f_percentage_down})" | bc -l) + local f_to=$(echo "${f_base} + (${f_base} / 100 * ${f_percentage_up})" | bc -l) + + g_num_is_between ${f_num} ${f_from} ${f_to} +}