From 03bcb6929e347a3498a6ea57b730f8e97447acd6 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Thu, 22 Feb 2024 15:10:20 +0100
Subject: [PATCH] update ph.toUnit: show value 0

---
 inc_pluginfunctions | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/inc_pluginfunctions b/inc_pluginfunctions
index 55b1b19..c7a7dcf 100644
--- a/inc_pluginfunctions
+++ b/inc_pluginfunctions
@@ -320,6 +320,12 @@ function ph.toUnit(){
     local _value=$1
     local _unit=$2
     local _digits=${3:-0}
+    local _dots
+
+    if [ "$_value" -eq "0" ]; then
+      echo "0"
+      return 0
+    fi
 
     local _multiply; _multiply=$( ph._getExp "$_value" )
     local _divisor;  _divisor=$(  ph._getExp "$_unit"  )
@@ -327,7 +333,6 @@ function ph.toUnit(){
     local _bc
     _bc="bc"
 
-    local _dots
 
     test $_digits -gt 0 && _dots=$( yes "." 2>/dev/null | head -$_digits | tr -d "\n" )
     test $_digits -gt 0 && _bc+=" -l | grep -o '.*\\.${_dots}'"
-- 
GitLab