Replacement for snprintf

lithium iodate whatdoiknow at
Wed Nov 6 17:05:34 UTC 2019

On Wednesday, 6 November 2019 at 13:25:38 UTC, berni44 wrote:
> a) I need to create some test. As far as I know, I've to 
> execute "export LANG=de_DE.UTF-8" (in bash, debian) to make it 
> use the german locale, which should replace the dot by a comma. 
> Unfortunately writefln!"%.10f"(0.1) still writes a dot instead 
> of the expected ",". Instead of "LANG" I tried several other 
> stuff, like LC_ALL or LC_NUMERIC. Any idea what I do wrong here?

If D wishes to behave the same as C, this is correct behavior. C 
requires the locale "C" to be activated at program startup.
The C-way to use the environment's locale is to call setlocale 
for the relevant category with an empty string for the locale 
e. g. setlocale(LC_ALL, "")

> b) How to query the current locale from D? Actually I only need 
> the number-separator in the current locale as a dchar. I found 
> core.stdc.locale but do not know how to use it.

You can query the current locale of a given category by calling 
setlocale with a null-pointer for the locale, it will return the 
currently set locale as a C-string.

The formatting-information is returned by localeconv(). Not sure 
why the docs don't show the members of lconv, but it contains 
decimal_point, which is a C-string of the decimal separator.
setlocale(LC_ALL, "de_DE.UTF-8");
prints ","

More information about the Digitalmars-d mailing list