Sets the members of a structure of type struct lconv with values appropriate for formatting numeric quantities according to the rules of the current locale.
#include <locale.h> struct lconv *localeconv (void);
The members of the structure are:
Member | Description |
---|---|
char *decimal_point | The radix character |
char *thousands_sep | The character used to separate groups of digits |
char *grouping | The string that defines how digits are grouped in non-monetary values. |
char *int_curr_symbol | The international currency symbol |
char *currency_ symbol | The local currency symbol |
char *mon_decimal_point | The radix character used to format monetary values |
char *mon_thousands_sep | The character used to separate groups of digits in monetary values |
char *mon_grouping | The string that defines how digits are grouped in a monetary value |
char *positive_sign | The string used to indicate a non-negative monetary value |
char *negative_sign | The string used to indicate a negative monetary value |
char int_frac_digits | The number of digits displayed after the radix character in a monetary value formatted with the international currency symbol. |
char frac_digits | The number of digits displayed after the radix character in a monetary value |
char p_cs_precedes | For positive monetary values, this is set to 1 if the local or international currency symbol precedes the number, and it is set to 0 if the symbol succeeds the number. |
char p_sep_by_space | For positive monetary values, this is set to 0 if there is no space between the currency symbol and the number. It is set to 1 if there is a space, and it is set to 2 if there is a space between the symbol and the sign string. |
char n_cs_ precedes | For negative monetary values, this is set to 1 if the local or international currency symbol precedes the number, and it is set to 0 if the symbol succeeds the number. |
char n_sep_by_space | For negative monetary values, this is set to 0 if there is no space between the currency symbol and the number. It is set to 1 if there is a space, and it is set to 2 if there is a space between the symbol and the sign string. |
char p_sign_posn | An integer used to indicate where the positive_sign string should be placed for a non-negative monetary quantity. |
char n_sign_posn | An integer used to indicate where the negative_sign string should be placed for a negative monetary quantity. |
Members of the structure of type char* are pointers to strings, any of which (except decimal_point) can point to "", indicating that the associated value is not available in the current locale or is zero length. Members of the structure of type char are positive numbers, any of which can be CHAR_MAX, indicating that the associated value is not available in the current locale. CHAR_MAX is defined in the <limits.h> header file.
When comparing values against CHAR_MAX, cast CHAR_MAX to type char as follows:
(char) CHAR_MAX
The members grouping and mon_grouping point to a string that defines the size of each group of digits when formatting a number. Each group size is separated by a semicolon (;). For example, if grouping points to the string 5;3 and the thousands_sep character is a comma (,), the number 123450000 would be formatted as 1,234,50000.
The elements of grouping and mon_grouping are interpreted as follows:
Value | Interpretation |
---|---|
CHAR_MAX | No further grouping is performed. |
0 | The previous element is to be used repeatedly for the remainder of the digits. |
other | The integer value is the number of digits that comprise the current group. The next element is examined to determine the size of the next group of digits before the current group. |
The values of p_sign_posn and n_sign_posn are interpreted as follows:
Value | Interpretation |
---|---|
0 | Parentheses surround the number and currency symbol. |
1 | The sign string precedes the number and currency symbol. |
2 | The sign string succeeds the number and currency symbol. |
3 | The sign string immediately precedes the number and currency symbol. |
4 | The sign string immediately succeeds the number and currency symbol. |
x | Pointer to the lconv structure. |
#include <stdlib.h> #include <stdio.h> #include <limits.h> #include <locale.h> #include <string.h> /* The following test program will set up the British English locale, */ /* and then extract the International Currency symbol and the */ /* International Fractional Digits fields for this locale and print them */ int main() { /* */ /* Declare variables */ /* */ char *return_val; struct lconv *lconv_ptr; /* */ /* Load a locale */ /* */ return_val = (char *)setlocale(LC_ALL,"en_GB.iso8859-1"); /* */ /* Did the locale load successfully? */ /* */ if (return_val == NULL) { /* */ /* It failed to load the locale */ /* */ printf("ERROR : The locale is unknown"); exit(EXIT_FAILURE); } /* */ /* Get the lconv structure from the locale */ /* */ lconv_ptr = (struct lconv *)localeconv(); /* */ /* Compare the international currency symbol string with an empty */ /* string. If they are equal then the international currency */ /* symbol is not defined in the locale. */ /* */ if(strcmp (lconv_ptr -> int_curr_symbol,"")) { printf("International Currency Symbol = %s\n", lconv_ptr -> int_curr_symbol); } else { printf("International Currency Symbol ="); printf("[Not available in this locale]\n"); } /* */ /* Compare International Fractional Digits with CHAR_MAX. If they */ /* are equal then International Fractional Digits are not defined in */ /* this locale. */ /* */ if ((unsigned char)(lconv_ptr -> int_frac_digits) != CHAR_MAX) { printf("International Fractional Digits = %d\n", lconv_ptr -> int_frac_digits); } else { printf("International Fractional Digits ="); printf("[Not available in this locale]\n"); } }
Running the example program produces the following result:
International Currency Symbol = GBP International Fractional Digits = 2