[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: locale-related printf bug when using formats with thousands grouping
From: |
Jim Meyering |
Subject: |
Re: locale-related printf bug when using formats with thousands grouping character |
Date: |
Wed, 12 Jan 2011 15:27:30 +0100 |
Eric Blake wrote:
> [adding bug-gnulib]
>
> On 01/11/2011 08:40 PM, Andrew J. Schorr wrote:
>> On Tue, Jan 11, 2011 at 10:31:26PM -0500, Andrew J. Schorr wrote:
>>> Using gawk 3.1.8 on Fedora 13 64-bit linux, I see this:
>>>
>>> bash-4.1$ (echo 1000000; echo 999999.9998071828) | gawk -v "sq='"
>>> {printf "%" sq ".2f\n", $1}'
>>> 1,000,000.00
>>> ,000,000.00
>>
>> Actually, this may be a glibc bug:
>>
>> bash-4.1$ printf "%'.2f\n" 999999.9998071828
>> ,000,000.00
That didn't demonstrate the problem for me, since I use LC_NUMERIC=C.
But when I make the locale choice explicit, I see the same bug:
$ LC_ALL=en_US.utf8 env printf %\'.0f 999999.5; echo
,000,000
Good one.
For the record, this affects the coreutils program (above)
as well as the built-in function of at least bash:
$ LC_ALL=en_US.utf8 bash -c "printf %\\'.0f 999999.5; echo"
,000,000
(zsh rejects the above, claiming that %' is an invalid directive)
When I experimented with numbers nearer 1000,
I found this (note the missing ","):
$ LC_ALL=en_US.utf8 bash -c "printf %\\'.0f 999.5; echo"
1000
Yet, with an input of 1000 or larger, you do get the ",":
$ LANG= LC_ALL=en_US.utf8 bash -c "printf %\\'.0f 1000; echo"
1,000