DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
Internationalization

# Numeric and monetary information

The ANSI C localeconv function returns a pointer to a structure containing information useful for formatting numeric and monetary information appropriate to the current locale's LC_NUMERIC and LC_MONETARY categories. (This is the only function whose behavior depends on more than one category.) For numeric values the structure describes the decimal-point (radix) character, the thousands separator, and where the separator(s) should be located. Other structure members describe how to format monetary values, as in the following, somewhat contrived example. Assuming setlocale has been called, the code

int thousands = 1;
int rest = 234;
int frac = 56;

struct lconv *lptr; lptr = localeconv();

printf("%s%d%c%d%c%d\n", lptr->currency_symbol, thousands, lptr->mon_thousands_sep[0], rest, lptr->mon_decimal_point[0], frac);

will print kr1.234,56 in a Norwegian locale, F 1.234,56 in a Dutch locale, and SFrs.1,234.56 in a Swiss locale. Check localeconv(3C) for details.

localeconv aside, functions that write or interpret printable floating values -- printf and scanf, for example -- will use a decimal-point character other than a period (``.'') when the LC_NUMERIC category of the current locale is other than ``"C"''. There is no provision for converting numeric values to printable form with thousands separator-type characters, but when converting from a printable form to an internal form, implementations are allowed to accept such additional forms, again in other than the ``"C"'' locale. Functions that make use of the decimal-point character are the printf and scanf families, atof, and strtod. Functions that are allowed implementation-defined extensions for the thousands separator are atof, atoi, atol, strtod, strtol, strtoul, and the scanf family.

Next topic: String collation
Previous topic: Date and time