Fellow monks,
We have run into a very strange issue with locales using comma as the decimal separator. Not sure where exactly the problem lies, but it seems that no matter if we say no locale; so we would be exempt from locale rules in a block — and this we need so numbers in JSON remain… well, numbers —, as long as we have an initialised Gtk2, we will get comma-separated floats.
~$ locale < ... all set to hu_HU.UTF-8 ... > [001] ~$ perl -e 'printf(q{%f}, 123.456);' 123.456000 [002] ~$ perl -e 'use locale; printf(q{%f}, 123.456);' 123.456000 [003] ~$ perl -e 'use locale; use POSIX; POSIX::setlocale("LC_ALL", "h +u_HU.UTF-8"); printf q{%f}, 123.456;' 123.456000 [004] ~$ perl -e 'use Gtk2 -init; printf(q{%f}, 123.456);' 123,456000
I might not know my way around locale, but I thought the line in 003 would result in a comma... In any case, the moment Gtk2 enters the game, like in 004, it turns into a comma. Then we experimented further:
[005] ~$ perl -e 'use Gtk2 -init; print unpack("H*", 123.789) . "\n";' 3132332c373839 [006] ~$ perl -e 'use locale; print unpack("H*", 123.789) . "\n";' 3132332e373839 [007] ~$ perl -e 'print unpack("H*", 123.789) . "\n";' 3132332e373839 [008] ~$ perl -e 'use Gtk2 -init; print unpack("H*", "123.789") . "\n" +;' 3132332e373839 [009] ~$ perl -e 'use Gtk2 -init; print unpack("H*", 123.789 . "") . " +\n";' 3132332c373839
Notice how even unpack already only knows about the commaed string, once Gtk2 is in play — we haven’t found a way to stringify the number (in our real-world use case: the result of a time() command — without the locale mangling it.
So... any ideas? What are we doing wrong? Is there a way around this without forcing the locale to be C (or something “proper”) before Gtk2 gets initialised, ie. without actually breaking the entire locale thing?
In reply to Perl, Gtk2 and locale — a bit of a mess by Ralesk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |