GNU Astronomy Utilities

4.11 Numeric locale

If your system locale is not English, it may happen that the ‘.’ is not used as the decimal separator of basic command-line tools for input or output. For example, in Spanish and some other languages the decimal separator (symbol used to separate the integer and fractional part of a number), is a comma. Therefore in such systems, some programs may print \(0.5\) as as ‘0,5’ (instead of ‘0.5’). This mainly happens in some core operating system tools like awk or seq depend on the locale. This can cause problems for other programs (like those in Gnuastro that expect a ‘.’ as the decimal separator).

To see the effect, please try the commands below. The first one will print \(0.5\) in your default locale’s format. The second set will use the Spanish locale for printing numbers (which will put a comma between the 0 and the 5). The third will use the English (US) locale for printing numbers (which will put a point between the 0 and the 5).

$ seq 0.5 1

$ export LC_NUMERIC=es_ES.utf8
$ seq 0.5 1

$ export LC_NUMERIC=en_US.utf8
$ seq 0.5 1

With the simple command below, you can check your current locale environment variables for specifying the formats of various things like date, time, monetary, telephone, numbers, etc. You can change any of these, by simply giving different values to the respective variable like above. For a more complete explanation on each variable, see

$ locale

To avoid these kinds of locale-specific problems (for example, another program not being able to read ‘0,5’ as half of unity), you can change the locale by giving the value of C to the LC_NUMERIC environment variable (or the lower-level/generic LC_ALL). You will notice that C is not a human-language and country identifier like en_US, it is the programming locale, which is well recognized by programmers in all countries and is available on all Unix-like operating systems (others may not be pre-defined and may need installation). You can set the LC_NUMERIC only for a single command (the first one below: simply defining the variable in the same line), or all commands within the running session (the second command below, or “exporting” it to all subsequent commands):

## Change the numeric locale, only for this 'seq' command.
$ LC_NUMERIC=C seq 0.5 1

## Change the locale to the standard, for all commands after it.
$ export LC_NUMERIC=C

If you want to change it generally for all future sessions, you can put the second command in your shell’s startup file. For more on startup files, please see Installation directory.