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. Format #include <locale.h> struct lconv *localeconv (void);
1 – Description
The localeconv function returns a pointer to the lconv structure defined in the <locale.h> header file. This structure should not be modified by the program. It is overwritten by calls to localeconv, or by calls to the setlocale function that change the LC_NUMERIC, LC_MONETARY, or LC_ALL categories. 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 nonmonetary values. char *int_curr_symbol The international currency symbol. char *currency_symbol The local currency symbol. char *mon_decimal_ The radix character used to format point monetary values. char *mon_thousands_ The character used to separate groups of sep 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 nonnegative 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 nonnegative 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. Be aware that the value of the CHAR_MAX macro in the <limits.h> header depends on whether the program is compiled with the /UNSIGNED_CHAR qualifier: o Use the CHAR_MAX macro as an indicator of a nonavailable value in the current locale only if the program is compiled without /UNSIGNED_CHAR (/NOUNSIGNED_CHAR is the default). o If the program is compiled with /UNSIGNED_CHAR, use the SCHAR_ MAX macro instead of the CHAR_MAX macro. In /NOUNSIGNED_CHAR mode, the values of CHAR_MAX and SCHAR_MAX are the same; therefore, comparison with SCHAR_MAX gives correct results regardless of the /[NO]UNSIGNED_CHAR mode used. 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.
2 – Return Value
x Pointer to the lconv structure.
3 – Example
#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