From b7bf00c5dc033406fd00d95e6a9dd8e663be3a4e Mon Sep 17 00:00:00 2001 From: katherine Date: Mon, 1 Feb 2016 21:10:31 -0700 Subject: rounding with calc --- .zshrc-linux-desktop | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.zshrc-linux-desktop b/.zshrc-linux-desktop index 28e251d..f92845b 100644 --- a/.zshrc-linux-desktop +++ b/.zshrc-linux-desktop @@ -43,8 +43,8 @@ mpd-filetypes() { if [[ ${counts[$i]} -eq 0 ]]; then percentages[$i]=0 else - # dunno how to make zsh math float without appending a . to integer numbers - percentages[$i]=$(calc -p "${counts[$i]} * 100 / $total" | tr -d '~' | cut -c -4) + percentages[$i]=$(calc -p "a=${counts[$i]} * 100 / $total; round(a, 4-digits(a), 16)"\ + | tr -d '~') fi # get widths for padding. @@ -70,7 +70,7 @@ mpd-filetypes() { done # print total - linelen=$(( $twidth + $cwidth + 9 )) + linelen=$(( $twidth + $cwidth + 10 )) for (( i=0; i < $linelen; i++ )); do echo -n "=" done -- cgit v1.2.3