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

Re: LC_NUMERIC vs locale ?



On 2009-11-30 16:25 +0100, Mathieu Malaterre wrote:

>   My computer is setup so that default locale is en_US.utf8. In order
> to do some testing with LC_NUMERIC. I decided to install more locale
> (dpkg-reconfigure locales). Now I have:
>
> $ locale -a
> C
> en_US.utf8
> fr_FR.utf8
> POSIX
>
> However I am still missing something to get LC_NUMERIC working. For
> instance in my shell:
>
>
> $ LC_NUMERIC=fr_FR.utf8  zsh -c 'float a=1; echo $(( a / 3 ))'
> 0.33333333333333331
>
> Which is clearly wrong.

It might not have been what you expected.

> What are the steps that I missed to get locale properly setup ?

None.  It is zsh that explicitly calls setlocale(LC_NUMERIC, "POSIX")
when doing floating point arithmetic, because otherwise scripts doing
that would depend on the locale.  This is documented in zshparam(1):

,----
| LC_NUMERIC <S>
| 	This variable  affects the decimal point  character and thousands
| 	separator character for  the formatted input/output functions and
| 	string conversion functions.  Note  that zsh ignores this setting
| 	when parsing floating point mathematical expressions.
`----

Sven


Reply to: