From 6133cac721f355aec0d6b5581fef90db34305f29 Mon Sep 17 00:00:00 2001 From: Kumar Date: Sat, 19 Feb 2022 07:35:04 +0530 Subject: [PATCH] Process: Handle rounding ambiguity between 99.9 and 100.0 Depending upon default behavior of the compiler and floating-point environment, compiler could round down the value between "99.9" and "100.0" to "99.0", instead of rounding it to the nearest value, "100.0". Note: The floating-point environment access and modification is only meaningful when "#pragma STD FENV_ACCESS" is set to "ON"[1]. Otherwise implementation is free to assume that floating-point control modes are always the default. So it would be a good idea to address the rounding ambiguity between "99.9" and "100.0" to become compiler agnostic. [1]: https://en.cppreference.com/w/c/numeric/fenv Credits: @Explorer09, thanks for the suggestion. --- Process.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Process.c b/Process.c index a3118b46..34c66bec 100644 --- a/Process.c +++ b/Process.c @@ -741,7 +741,9 @@ void Process_printPercentage(float val, char* buffer, int n, int* attr) { xSnprintf(buffer, n, "%4.1f ", val); } else { *attr = CRT_colors[PROCESS_MEGABYTES]; - xSnprintf(buffer, n, "%4d ", (int)val); + if (val < 100.0F) + val = 100.0F; // Don't round down and display "val" as "99". + xSnprintf(buffer, n, "%4.0f ", val); } } else { *attr = CRT_colors[PROCESS_SHADOW];