X-Git-Url: https://git.xinqibao.xyz/slstatus.git/blobdiff_plain/103945e7bb8d3a4198cf175b8f6be09fe53ab9e1..57f69e900bf7e3e7c60a720bf09f2134b724c5cc:/components/battery.c diff --git a/components/battery.c b/components/battery.c index 6105a37..8bfe42a 100644 --- a/components/battery.c +++ b/components/battery.c @@ -83,7 +83,7 @@ battery_remaining(const char *bat) { int charge_now, current_now, m, h; - float timeleft; + double timeleft; char path[PATH_MAX], state[12]; if (esnprintf(path, sizeof(path), @@ -107,9 +107,13 @@ return NULL; } - timeleft = (float)charge_now / (float)current_now; + if (current_now == 0) { + return NULL; + } + + timeleft = (double)charge_now / (double)current_now; h = timeleft; - m = (timeleft - (float)h) * 60; + m = (timeleft - (double)h) * 60; return bprintf("%dh %dm", h, m); }