From 950460691e3c962ef35c9aaea2d950e7a7e567ea Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 10 Jan 2005 08:27:03 +0000 Subject: [PATCH] Fix %' grouping in printf(). I hope this finally takes care of it. --- src/lib/stdio.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/lib/stdio.c b/src/lib/stdio.c index bae257f..98b6303 100644 --- a/src/lib/stdio.c +++ b/src/lib/stdio.c @@ -469,23 +469,21 @@ format_integer (uintmax_t value, bool negative, const struct integer_base *b, const char *signifier; /* b->signifier or "". */ int precision; /* Rendered precision. */ int pad_cnt; /* # of pad characters to fill field width. */ - int group_cnt; /* # of digits grouped so far. */ + int digit_cnt; /* # of digits output so far. */ /* Accumulate digits into buffer. This algorithm produces digits in reverse order, so later we will output the buffer's content in reverse. This is also the reason that later we append zeros and the sign. */ cp = buf; - group_cnt = 0; + digit_cnt = 0; while (value > 0) { - if ((c->flags & GROUP) && group_cnt++ == b->group) - { - *cp++ = ','; - group_cnt = 0; - } + if ((c->flags & GROUP) && digit_cnt > 0 && digit_cnt % b->group == 0) + *cp++ = ','; *cp++ = b->digits[value % b->base]; value /= b->base; + digit_cnt++; } /* Append enough zeros to match precision. -- 2.30.2