From da2b8e342efa952dea4b664fac6179d75804a2b9 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 23 Nov 2015 18:10:09 +0100 Subject: [PATCH] Arithmetics in ZSH 101: If you want to calculate a percentage, multiply the numerator with 100 _before_ the devision. With that method there is no need for hacks to convert the numerator into a float. --- powerlevel9k.zsh-theme | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7ce82e0a..c1d1abf0 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -240,10 +240,8 @@ prompt_battery() { local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }') if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then - typeset -F 2 current_capacity - current_capacity="$current_capacity"+0.00001 typeset -i 10 bat_percent - bat_percent=$(( (current_capacity / max_capacity) * 100 )) + bat_percent=$(( (current_capacity * 100) / max_capacity )) fi # logic for string output