From 36fb57d1b9f52c61615cc202eb01b92044b7d145 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 6 Dec 2025 06:19:54 -0500 Subject: alf: percent(). --- src/alf.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/alf.c b/src/alf.c index c3e721c..4144d65 100644 --- a/src/alf.c +++ b/src/alf.c @@ -180,6 +180,10 @@ void convert_eols(void) { } } +int percent(unsigned int out, unsigned int in) { + return 100 - (int)((float)out / (float)in * 100.0); +} + void crunch_file(const char *filename_arg) { strncpy(in_filename, filename_arg, PATH_MAX); @@ -242,8 +246,7 @@ void crunch_file(const char *filename_arg) { if(opt_verbose) { printf(" %u/%u (%d%%)\n", - input_len, output_len, - 100 - (int)((float)output_len / (float)input_len * 100.0)); + input_len, output_len, percent(output_len, input_len)); } total_in += input_len; @@ -351,7 +354,7 @@ int main(int argc, char **argv) { printf("Compressed %d file%s: ", file_count, file_count == 1 ? "" : "s"); printf("%u/%u (%d%%)\n", total_in, total_out, - 100 - (int)((float)total_out / (float)total_in * 100.0)); + percent(total_out, total_in)); print_elapsed_time(); if(backup_msg) { printf("Backed up old '%s' to '%s~'.\n", out_filename, out_filename); -- cgit v1.2.3