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.
Would you like to create a PR for this?
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.
(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);
(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.
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.