[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What controls the decimal delimiter?
- From: Marc Balmer <marc@...>
- Date: Mon, 23 Jan 2023 12:05:17 +0100
> Am 23.01.2023 um 11:22 schrieb Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>:
>
>> When I output a number value, e.g. 42.0, it is normally output with a decimal point.
>
> The locale controls that.
>
> % lua
>> tonumber("42,0")
> nil
>> os.setlocale"de_DE"
> de_DE
>> tonumber("42,0")
> 42,0
>> tonumber("42.0")
> 42,0
Well, that is converting a string to a number. I had the problem when Lua converts a number to a string, i.e. the other way round.
Lua uses *(localconv())->decimal_point to get a localized decimal point and insert it into the string. Most Linux distributions return a point when the LANG environment variable is not set. But openSUSE Leap returns a comma if LANG is not set. As soon as you set LANG, it will return whatever is configured in that locale. So it uses a different default decimal limiter than most other Linux distributions, it seems.
The reason was actually a funny one (but took me quite some time to find out):
I store some numbers (representing coins of a certain currency) in a number array in PostgreSQL. The syntax to do so in SQL is „{5.0, 2.0, 1.0}“. Now, when Lua gives you commas instead of points, you get „{5,0, 2,0, 1,0}“, so it will insert six numbers instead of three.