From a3834cdfb0d1bfc7f3cd30a78410667caf1236ef Mon Sep 17 00:00:00 2001 From: olli <> Date: Sun, 23 Jun 2024 13:02:23 +0200 Subject: [PATCH] exponential2normal --- gaboshlib/g_num_exponential2normal.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 gaboshlib/g_num_exponential2normal.sh diff --git a/gaboshlib/g_num_exponential2normal.sh b/gaboshlib/g_num_exponential2normal.sh new file mode 100644 index 0000000..c30ea1a --- /dev/null +++ b/gaboshlib/g_num_exponential2normal.sh @@ -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 +}