This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/23432] New: missing thousands separator in printf output for leading zeros of integers


https://sourceware.org/bugzilla/show_bug.cgi?id=23432

            Bug ID: 23432
           Summary: missing thousands separator in printf output for
                    leading zeros of integers
           Product: glibc
           Version: 2.27
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libc
          Assignee: unassigned at sourceware dot org
          Reporter: vincent-srcware at vinc17 dot net
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

When leading zeros are output by printf on an integer, thanks to the precision
field, the thousands' grouping characters in the part before the first non-zero
digit are missing.

Consider the following program:

#include <stdio.h>
#include <locale.h>

int main(int argc, char **argv)
{
  setlocale (LC_ALL, "");
  printf ("%'.17d\n", 123456789);
  return 0;
}

With LC_ALL=en_US.utf8 I get

000000123,456,789

instead of

000,000,123,456,789

POSIX http://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html
says:

  An optional precision that gives the minimum number of digits to appear for
the d, i, o, u, x, and X conversion specifiers[...]

and

  (The <apostrophe>.) The integer portion of the result of a decimal conversion
( %i, %d, %u, %f, %F, %g, or %G ) shall be formatted with thousands' grouping
characters. [...]

It does not mention any special treatment of the leading zeros compared to the
other digits. And even though for readability, the thousands' grouping
character is useless before the first non-zero digit, I assume that it may be
important for alignment with other numbers and in other cases, such as
implementing multiple precision in radix 1000^n (say, each radix 1000^3 digit
is output with "%'.9d"). Thus I don't think there is a defect in POSIX and the
real intent is to output these thousands' grouping characters.

Note: When using 0 padding, e.g. "%017d", I assume that the current behavior is
correct, because this is just padding, not additional digits.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]