1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-11-26 05:50:07 +00:00

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.

This commit is contained in:
Dominik Ritter 2015-11-23 18:10:09 +01:00
parent 239aa29a12
commit da2b8e342e

View file

@ -240,10 +240,8 @@ prompt_battery() {
local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }') local current_capacity=$(echo $raw_data | grep CurrentCapacity | awk '{ print $5 }')
if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then if [[ -n "$max_capacity" && -n "$current_capacity" ]]; then
typeset -F 2 current_capacity
current_capacity="$current_capacity"+0.00001
typeset -i 10 bat_percent typeset -i 10 bat_percent
bat_percent=$(( (current_capacity / max_capacity) * 100 )) bat_percent=$(( (current_capacity * 100) / max_capacity ))
fi fi
# logic for string output # logic for string output