swl has asked for the wisdom of the Perl Monks concerning the following question:
Is there an sprintf implementation available for Perl that is independent of any numeric locale settings? i.e. where sprintf "%.2g", 3.1415926 returns 3.14 and not 3,14 on locales that use a comma as the radix character.
For context, I recently hit issues with a Gtk2 interface to an application was setting the numeric locale to match a user's settings. The application uses sprintf to reduce the numeric precision of values to use as hash keys for a simple index, which then had knock-on effects when the index keys were used numerically. There were other locale effects, but that was the main one.
That specific case is now avoided since I discovered Gtk2->disable_setlocale, and I do realise that numeric locales affect more than just sprintf, but it might still be useful to have a locale independent version.
I found nothing when checking metacpan, but there look to be external libraries that allow one to specify a locale as an argument.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A locale independent sprintf?
by syphilis (Archbishop) on Jul 29, 2020 at 01:21 UTC | |
by swl (Parson) on Jul 29, 2020 at 03:11 UTC | |
by kcott (Archbishop) on Jul 29, 2020 at 03:37 UTC | |
by swl (Parson) on Jul 29, 2020 at 04:06 UTC | |
by kcott (Archbishop) on Jul 29, 2020 at 09:05 UTC | |
| |
by swl (Parson) on Jul 29, 2020 at 05:11 UTC | |
Re: A locale independent sprintf?
by salva (Canon) on Jul 29, 2020 at 08:05 UTC | |
by swl (Parson) on Jul 29, 2020 at 08:48 UTC | |
by salva (Canon) on Jul 29, 2020 at 08:58 UTC | |
by swl (Parson) on Jul 29, 2020 at 11:27 UTC | |
by jcb (Parson) on Jul 30, 2020 at 01:51 UTC | |
Re: A locale independent sprintf?
by bliako (Monsignor) on Jul 29, 2020 at 06:54 UTC | |
by swl (Parson) on Jul 29, 2020 at 07:12 UTC |