From 48ff4893d34eece1f7a59c649aa580f66d9573a9 Mon Sep 17 00:00:00 2001 From: TT Date: Tue, 25 Feb 2020 08:41:22 +0900 Subject: [PATCH] feat: force putting trailing zeros on float value --- chprintf.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/chprintf.c b/chprintf.c index 6ba7efd..39b4fc9 100644 --- a/chprintf.c +++ b/chprintf.c @@ -36,6 +36,9 @@ // ' ' Prepends a space for positive signed-numeric types. positive = ' ', negative = '-'. This flag is ignored if the + flag exists. //#define CHPRINTF_USE_SPACE_FLAG +// Force putting trailing zeros on float value +#define CHPRINTF_FORCE_TRAILING_ZEROS + #define MAX_FILLER 11 #define FLOAT_PRECISION 9 @@ -161,12 +164,14 @@ static char *ftoa(char *p, float num, uint32_t precision) { // Fix rounding error if get if (k>=multi){k-=multi;l++;} p = long_to_string_with_divisor(p, l, 10, 0); - if (precision && k){ + if (precision){ *p++ = '.'; p=long_to_string_with_divisor(p, k, 10, precision); +#ifndef CHPRINTF_FORCE_TRAILING_ZEROS // remove zeros at end while (p[-1]=='0') p--; if (p[-1]=='.') p--; +#endif } return p; }