From 85dc7cf0749661e799c488a515a12ab9353ee5b2 Mon Sep 17 00:00:00 2001 From: Marco Paland Date: Fri, 20 Apr 2018 13:28:55 +0200 Subject: fix(printf): fixed floating point sign handling --- printf.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'printf.c') diff --git a/printf.c b/printf.c index 69c7ea7..418386a 100644 --- a/printf.c +++ b/printf.c @@ -303,16 +303,16 @@ static size_t _ftoa(double value, char* buffer, size_t maxlen, unsigned int prec break; } } - + // pad leading zeros - while (!(flags & FLAGS_LEFT) && (len < prec) && (len < PRINTF_FTOA_BUFFER_SIZE)) { - buf[len++] = '0'; - } while (!(flags & FLAGS_LEFT) && (flags & FLAGS_ZEROPAD) && (len < width) && (len < PRINTF_FTOA_BUFFER_SIZE)) { buf[len++] = '0'; } // handle sign + if ((len == width) && (negative || (flags & FLAGS_PLUS) || (flags & FLAGS_SPACE))) { + len--; + } if (len < PRINTF_FTOA_BUFFER_SIZE) { if (negative) { buf[len++] = '-'; -- cgit v1.2.3