Comment #0 by bearophile_hugs — 2011-11-09T20:11:23Z
Quotation from: http://linux.die.net/man/3/printf
> For some numeric conversions a radix character ("decimal point") or thousands'
> grouping character is used. The actual character used depends on the LC_NUMERIC
> part of the locale. The POSIX locale uses '.' as radix character, and does not
> have a grouping character. Thus,
>
> printf("%'.2f", 1234567.89);
>
> results in "1234567.89" in the POSIX locale, in "1234567,89" in the nl_NL
> locale, and in "1.234.567,89" in the da_DK locale.
Maybe it's good to support this syntax in writef/writefln too. But I don't know if using the locale is a good idea here.
Comment #1 by lt.infiltrator — 2014-03-19T21:36:35Z
Would you like to create a PR for this?
Comment #2 by bugzilla — 2021-02-06T19:57:09Z
Meanwhile
writef("%.2,f", 1234567.89);
does this grouping. Result: "1,234,567.89" It does not support a locale though. And if I should guess, it will never do, because that would make the functions non pure. A possible approach would probably be, to add a special module for localization that calls writef and modifies the result according to the locale.
Comment #3 by andrei — 2021-02-07T03:14:11Z
(In reply to Berni44 from comment #2)
> Meanwhile
>
> writef("%.2,f", 1234567.89);
>
> does this grouping. Result: "1,234,567.89" It does not support a locale
> though. And if I should guess, it will never do, because that would make the
> functions non pure. A possible approach would probably be, to add a special
> module for localization that calls writef and modifies the result according
> to the locale.
A way to keep purity with locales would be to pass the locale into the functions, e.g.
writef(mylocale, "%.2,f", 1234567.89);
Comment #4 by bugzilla — 2021-02-07T07:48:31Z
(In reply to Andrei Alexandrescu from comment #3)
> A way to keep purity with locales would be to pass the locale into the
> functions, e.g.
>
> writef(mylocale, "%.2,f", 1234567.89);
Sure, but it would make the functions much more complicated - for example think of different digit shapes used in some areas of the world or even printing from right to left (what's the minus-flag supposed to do in that case?)... I'd prefer to have localization in a wrapper in a different module.
Comment #5 by bugzilla — 2021-04-11T08:37:58Z
I'm closing this, because the support for grouping exists and localization is a different thing. I opened a new one for this: Issue 21819.