exponential2normal
This commit is contained in:
parent
0a0bc8d193
commit
a3834cdfb0
18
gaboshlib/g_num_exponential2normal.sh
Normal file
18
gaboshlib/g_num_exponential2normal.sh
Normal file
@ -0,0 +1,18 @@
|
||||
function g_num_exponential2normal {
|
||||
|
||||
[ -z "$1" ] && return 1
|
||||
# if there is a exponential number (for example 9.881e-05) convert it to "normal" notation
|
||||
if [[ "$1" =~ ^(-)?(\.)?[0-9]+(\.)?([0-9]+)?(e-[0-9]+)?$ ]]
|
||||
then
|
||||
# convert
|
||||
printf -v f_g_num_exponential2normal_result -- "%.12f" "$1"
|
||||
# remove ending 0
|
||||
if [[ $f_g_num_exponential2normal_result =~ \. ]]
|
||||
f_g_num_exponential2normal_result=${f_g_num_exponential2normal_result%%+(0)}
|
||||
f_g_num_exponential2normal_result=${f_g_num_exponential2normal_result%%.}
|
||||
return 0
|
||||
else
|
||||
f_g_num_exponential2normal_result=$1
|
||||
return 1
|
||||
fi
|
||||
}
|
Loading…
Reference in New Issue
Block a user