lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

tostring is implemented in terms of sprintf(3). So it would depend on
whether sprintf were locale-aware or not. Some are.

(From the man page on some random Linux machine I happen to have handy. I
think they meant "radix" instead of "radic" in the first line.)

       For some numeric conversion a  radic  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.

I sympathise: CSV is a crock. Locales are a crock. But life's like that.

Here are a few tips:

1) If you're trying to import into Excel, you're going to run into locale
problems, one end or the other. My recommendation is to use tabs as
separators instead of commas. That gives you a fighting chance.

2) You can completely eliminate the decimal indicator by using format.
Specify the "e" or "E" format with 0 precision (eg. %16.0E) A conforming
sprintf will not produce either period or comma. It shouldn't produce
grouping characters, either.

3) Use the POSIX locale. That won't help you import but it might help you
export. I think there's a Lua locale interface floating about somewhere. If
you're running on Windows, I have no advice, but there ought to be a way of
selecting it there, too.


                    Markus Huber                                                                                          
                    <        To:     Multiple recipients of list <>            
                    >                           cc:                                                                       
                    Sent by:                    Subject:     tostring() - locale                                          
                    14/04/02 14.31                                                                                        
                    Please respond to                                                                                     

Is tostring() depending on locale? e.g. returns tostring(4.7) always
"4.7" or possible "4,7"? In CSV files 4,7 for numbers are not useable.