fixes
This commit is contained in:
parent
e1dbc5b9d1
commit
2563371b0e
@ -1,14 +1,18 @@
|
||||
function g_num_valid_number {
|
||||
[ -z "$1" ] && return 1
|
||||
local f_arg=( "0" "$@" )
|
||||
local i
|
||||
for (( i=0; i<=$#; i++ ))
|
||||
local arg
|
||||
for arg in "$@"
|
||||
do
|
||||
if ! [[ ${f_arg[$i]} =~ ^(-)?(\.)?[0-9]+(\.)?([0-9]+)?$ ]]
|
||||
if ! [[ $arg =~ ^(-)?(\.)?[0-9]+(\.)?([0-9]+)?$ ]]
|
||||
then
|
||||
echo "\"${f_arg[$i]}\": Not a valid number" 1>&2
|
||||
echo "\"$arg\": Not a valid number" 1>&2
|
||||
g_traceback
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "No argument given" 1>&2
|
||||
g_traceback
|
||||
return 2
|
||||
fi
|
||||
}
|
||||
|
@ -5,11 +5,18 @@ function g_percentage-diff {
|
||||
local g_to=$2
|
||||
unset g_percentage_diff_result
|
||||
g_num_valid_number "$g_from" "$g_to" || return 1
|
||||
g_calc "${g_from} == 0"
|
||||
[ ${g_calc_result} -eq 1 ] && return 1
|
||||
g_calc "${g_to} == 0"
|
||||
[ ${g_calc_result} -eq 1 ] && return 1
|
||||
g_calc "100/${g_from}*(${g_to}-${g_from})"
|
||||
#g_percentage_diff_result=$(printf -- "%.2f" "${g_calc_result}")
|
||||
printf -v g_percentage_diff_result -- "%.2f" "${g_calc_result}"
|
||||
g_calc "$g_from == 0"
|
||||
if [ $g_calc_result -eq 1 ]
|
||||
then
|
||||
g_echo_note "$0: ERR: g_from=$g_from"
|
||||
return 2
|
||||
fi
|
||||
g_calc "$g_to == 0"
|
||||
if [ $g_calc_result -eq 1 ]
|
||||
then
|
||||
g_echo_note "$0: ERR: g_to=$g_to"
|
||||
return 3
|
||||
fi
|
||||
g_calc "100 / $g_from * ( $g_to - ( $g_from ) )" || return 4
|
||||
printf -v g_percentage_diff_result -- "%.2f" $g_calc_result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user