From 82ba2d4abe6ed3db561313571f0f63e5f0111099 Mon Sep 17 00:00:00 2001 From: "-T.K.-" Date: Thu, 6 Jun 2024 15:28:45 -0700 Subject: [PATCH] ADD: update float printing --- nn/src/nn_print.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/nn/src/nn_print.c b/nn/src/nn_print.c index bb5979e..731b5ea 100644 --- a/nn/src/nn_print.c +++ b/nn/src/nn_print.c @@ -12,29 +12,20 @@ void NN_printFloat(float v, int16_t num_digits) { long int_part = (long)v; float fractional_part = v - int_part; - // Count the number of digits in the integer part - long temp = int_part; - int int_digits = (int_part == 0) ? 1 : 0; // Handle zero as a special case - while (temp > 0) { - int_digits++; - temp /= 10; - } - // Print the integer part printf("%ld", int_part); - // Calculate the number of fractional digits we can print - int fractional_digits = num_digits - int_digits; - if (fractional_digits > 0) { + if (num_digits > 0) { printf("."); // Print the decimal point + } - // Handle the fractional part - while (fractional_digits-- > 0) { - fractional_part *= 10; - int digit = (int)(fractional_part); - printf("%d", digit); - fractional_part -= digit; - } + // Handle the fractional part + while (num_digits > 0) { + num_digits -= 1; + fractional_part *= 10; + int digit = (int)(fractional_part); + printf("%d", digit); + fractional_part -= digit; } }