If that's a zsh
shell script, you can use the $langinfo
special associative array in the zsh/langinfo
module:
zmodload zsh/langinfo
radix=$langinfo[RADIXCHAR]
(that maps to the standard nl_langinfo(RADIXCHAR)
, see man nl_langinfo
on your system for details; $langinfo[THOUSEP]
for the thousand separator).
In a bash
script (would also work in zsh
), you should be able to get it without forking a separate process using the printf
builtin:
printf -v radix %.1f 1 && radix=${radix:1:1}
To convert a number from the user's locale format to the C locale format, with the ksh93 shell, you could do it like:
$ locale title
German locale for Germany
$ x=1.123.456,78 ksh -c 'typeset -F x="$x"; LC_ALL=C; printf "%.23g\n" "$x"'
1123456.78
tcsh
in ..., oh my, you definitely can say that I'm OLD!!!LC_ALL=C
environment?