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.

pull/22/head
Dominik Ritter 9 years ago
parent 239aa29a12
commit da2b8e342e

@ -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

Loading…
Cancel
Save