Fixed incorrect truncation

This commit is contained in:
Rob Pearce 2022-08-29 11:01:10 +10:00
parent fba28d7ee0
commit 64ac879faa
1 changed files with 36 additions and 12 deletions

View File

@ -65,10 +65,22 @@ if [[ $mode == "s" ]]; then
diagram="${diagram}[server]\n"
eq="${eq} * 100"
answer=$(echo "scale=9; $eq" | bc)
if [[ $answer == 99.* ]]; then
answershort=$(echo "$answer" | tr -dc '9.')
else
answershort=$answer
fi
if [[ $answershort == 99.* ]]; then
nines=$(echo $answershort | tr -d -C 9 | wc -c | tr -d ' ')
[[ $nines -eq 1 ]] && ess="" || ess="s"
ninestext="${nines} nine${ess}"
if [[ -n $HAVE_BASHTOOLS ]]; then
ninestext=" (^b\"${nines} nine${ess}\"^p)"
else
ninestext=" (\"${nines} nine${ess}\")"
fi
else
ninestext=""
fi
if [[ -n $HAVE_BASHTOOLS ]]; then
@ -77,7 +89,7 @@ if [[ $mode == "s" ]]; then
echo
csecho -e "$WHITE" "^b${UNDERLINE}Availability^p\n"
inform "^bEquation:^p ${eq}"
inform "^bAvailability:^p ${answershort}% (^b\"$ninestext\"^p)"
inform "^bAvailability:^p ${answershort}% $ninestext"
echo
else
echo "Architecture"
@ -88,7 +100,7 @@ if [[ $mode == "s" ]]; then
echo "Availability"
echo "------------"
echo "* Equation: ${eq}"
echo "* Availability: ${answershort}% (\"$ninestext\")"
echo "* Availability: ${answershort}% $ninestext"
echo
fi
elif [[ $mode == "p" ]]; then
@ -178,10 +190,22 @@ elif [[ $mode == "p" ]]; then
eq="(1 - (1 - (${sysuptime}/100))^${nsites})*100"
answer=$(echo "scale=15; $eq" | bc)
if [[ $answer == 99.* ]]; then
answershort=$(echo "$answer" | tr -dc '9.')
else
answershort=$answer
fi
if [[ $answershort == 99.* ]]; then
nines=$(echo $answershort | tr -d -C 9 | wc -c | tr -d ' ')
[[ $nines -eq 1 ]] && ess="" || ess="s"
ninestext="${nines} nine${ess}"
if [[ -n $HAVE_BASHTOOLS ]]; then
ninestext=" (^b\"${nines} nine${ess}\"^p)"
else
ninestext=" (\"${nines} nine${ess}\")"
fi
else
ninestext=""
fi
if [[ -n $HAVE_BASHTOOLS ]]; then
@ -190,7 +214,7 @@ elif [[ $mode == "p" ]]; then
echo
csecho -e "$WHITE" "^b${UNDERLINE}Availability^p\n"
inform "^bEquation:^p ${eq}"
inform "^bAvailability:^p ${answershort}% (^b\"$ninestext\"^p)"
inform "^bAvailability:^p ${answershort}% $ninestext)"
else
echo "Architecture"
echo "------------"
@ -200,7 +224,7 @@ elif [[ $mode == "p" ]]; then
echo "Availability"
echo "------------"
echo "Equation: ${eq}"
echo "Availability: ${answershort}% (\"$ninestext\")"
echo "Availability: ${answershort}% $ninestext"
fi
echo
elif [[ $mode == "i" ]]; then