From 67c2c1a7ead6bcdcd07080e581013fa7a0b58b6f Mon Sep 17 00:00:00 2001 From: Julien Lequertier Date: Sun, 10 Feb 2013 17:59:37 +0100 Subject: Added option to show battery capacity without decimals --- src/print_battery_info.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/print_battery_info.c') diff --git a/src/print_battery_info.c b/src/print_battery_info.c index 1545609..d4b091b 100644 --- a/src/print_battery_info.c +++ b/src/print_battery_info.c @@ -30,7 +30,7 @@ * worn off your battery is. * */ -void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity) { +void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char *path, const char *format, int low_threshold, char *threshold_type, bool last_full_capacity, bool integer_battery_capacity) { time_t empty_time; struct tm *empty_tm; char buf[1024]; @@ -130,7 +130,11 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char (void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status)); float percentage_remaining = (((float)remaining / (float)full_design) * 100); - (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining); + if (integer_battery_capacity) { + (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining); + } else { + (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining); + } if (present_rate > 0) { float remaining_time; -- cgit v1.2.3