diff options
author | Dominik Ritter <dritter03@googlemail.com> | 2015-11-23 20:10:09 +0300 |
---|---|---|
committer | Dominik Ritter <dritter03@googlemail.com> | 2015-11-23 20:10:09 +0300 |
commit | da2b8e342efa952dea4b664fac6179d75804a2b9 (patch) | |
tree | baa2e6291af990c0eadb8269430d221e429f3ebd | |
parent | 239aa29a1287d58ad61e6b9ff342fb7a7f2bf31e (diff) |
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.
-rwxr-xr-x | powerlevel9k.zsh-theme | 4 |
1 files changed, 1 insertions, 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 |