LOCALECONV(3C) | Standard C Library Functions | LOCALECONV(3C) |
localeconv - get numeric formatting information
#include <locale.h> struct lconv *localeconv(void);
The localeconv() function sets the components of an object with type struct lconv (defined in <locale.h>) with the values appropriate for the formatting of numeric quantities (monetary and otherwise) according to the rules of the current locale (see setlocale(3C)). The definition of struct lconv is given below (the values for the fields in the "C" locale are given in comments).
char *decimal_point; /* "." */ char *thousands_sep; /* "" (zero length string) */ char *grouping; /* "" */ char *int_curr_symbol; /* "" */ char *currency_symbol; /* "" */ char *mon_decimal_point; /* "" */ char *mon_thousands_sep; /* "" */ char *mon_grouping; /* "" */ char *positive_sign; /* "" */ char *negative_sign; /* "" */ char int_frac_digits; /* CHAR_MAX */ char frac_digits; /* CHAR_MAX */ char p_cs_precedes; /* CHAR_MAX */ char p_sep_by_space; /* CHAR_MAX */ char n_cs_precedes; /* CHAR_MAX */ char n_sep_by_space; /* CHAR_MAX */ char p_sign_posn; /* CHAR_MAX*/ char n_sign_posn; /* CHAR_MAX */
The following members are also available to SUSv3-conforming applications. See standards(7)
char int_p_cs_precedes; /* CHAR_MAX */ char int_p_sep_by_space; /* CHAR_MAX */ char int_n_cs_precedes; /* CHAR_MAX */ char int_n_sep_by_space; /* CHAR_MAX */ char int_p_sign_posn; /* CHAR_MAX */ char int_n_sign_posn; /* CHAR_MAX */
The members of the structure with type char * are strings, any of which (except decimal_point) can point to a null string (""), to indicate that the value is not available in the current locale or is of zero length. The members with type char are non-negative numbers, any of which can be CHAR_MAX (defined in the <limits.h> header) to indicate that the value is not available in the current locale. The members are the following:
char *decimal_point
char *thousands_sep
char *grouping
char *int_curr_symbol
char *currency_symbol
char *mon_decimal_point
char *mon_thousands_sep
char *mon_grouping
char *positive_sign
char *negative_sign
char int_frac_digits
char frac_digits
char p_cs_precedes
char p_sep_by_space
char n_cs_precedes
char n_sep_by_space
char p_sign_posn
char n_sign_posn
char int_p_cs_precedes
char int_n_cs_precedes
char int_p_sep_by_space
char int_n_sep_by_space
char int_p_sign_posn
char int_n_sign_posn
The elements of grouping and mon_grouping are interpreted according to the following:
{CHAR_MAX}
0
other
The values of p_sep_by_space, n_sep_by_space, int_p_sep_by_space, and int_n_sep_by_space are interpreted according to the following:
0
1
2
In an SUSv3-conforming application, for int_p_sep_by_space and int_n_sep_by_space, the fourth character of int_curr_symbol is used instead of a space.
The values of p_sign_posn, n_sign_posn, int_p_sign_posn, and int_n_sign_posn are interpreted according to the following:
0
1
2
3
4
The localeconv() function returns a pointer to the filled-in object. The structure pointed to by the return value may be overwritten by a subsequent call to localeconv().
Example 1 Rules used by four countries to format monetary quantities.
The following table illustrates the rules used by four countries to format monetary quantities.
Country | Positive | Negative | International |
Italy (IT) | L.1.234 | −L.1.234 | ITL.1.234 |
Netherlands (NE) | F 1.234,56 | F −1.234,56 | NLG 1.234,56 |
Norway (NO) | kr1.234,56 | kr1.234,56− | NOK 1.234,56 |
Switzerland (SW) | SFrs.1,234.56 | SFrs.1,234.56C | CHF 1,234.56 |
For these four countries, the respective values for the monetary members of the structure returned by localeconv() are as follows:
IT | NE | NO | SW | |
int_curr_symbol | "ITL." | "NLG " | "NOK " | "CHF " |
currency_symbol | "L." | "F" | "kr" | "SFrs." |
mon_decimal_point | "" | "," | "," | "." |
mon_thousands_sep | "." | "." | "." | "," |
mon_grouping | "\3" | "\3" | "\3" | "\3" |
positive_sign | "" | "" | "" | "" |
negative_sign | "-" | "-" | "-" | "C" |
int_frac_digits | 0 | 2 | 2 | 2 |
frac_digits | 0 | 2 | 2 | 2 |
p_cs_precedes | 1 | 1 | 1 | 1 |
p_sep_by_space | 0 | 1 | 0 | 0 |
n_cs_precedes | 1 | 1 | 1 | 1 |
n_sep_by_space | 0 | 1 | 0 | 0 |
p_sign_posn | 1 | 1 | 1 | 1 |
n_sign_posn | 1 | 4 | 2 | 2 |
int_p_cs_precedes | 1 | 1 | 1 | 1 |
int_n_cs_precedes | 1 | 1 | 1 | 1 |
int_p_sep_by_space | 0 | 0 | 0 | 0 |
int_n_sep_by_space | 0 | 0 | 0 | 0 |
int_p_sign_posn | 1 | 1 | 1 | 1 |
int_n_sign_posn | 1 | 4 | 4 | 2 |
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
CSI | Enabled |
Interface Stability | Standard |
MT-Level | MT-Safe with exceptions |
The localeconv() function can be used safely in multithreaded applications, as long as setlocale(3C) is not being called to change the locale.
December 12, 2003 | OmniOS |