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} +}