C <locale.h> - lconv() Type
The C <locale.h> lconv type is a structure holding formatting information on how numeric values (both monetary and non-monetary) are to be written. The localeconv() function returns an object of this type. The structure contains following members:
Non-monetary numeric formatting members
Type | Member | Description |
---|---|---|
char* | decimal_point | The character used as the decimal point. |
char* | thousands_sep | The character used to separate groups of digits before the decimal point. |
char* | grouping | A string whose elements indicate the sizes of digit groups. |
Monetary numeric formatting members
Type | Member | Description |
---|---|---|
char* | mon_decimal_point | The character used as the decimal point. |
char* | mon_thousands_sep | The character used to separate groups of digits before the decimal point. |
char* | mon_grouping | A string whose elements indicate the sizes of digit groups. |
char* | positive_sign | A string used to indicate non-negative monetary quantity. |
char* | negative_sign | A string used to indicate negative monetary quantity. |
Local monetary numeric formatting members
Type | Member | Description |
---|---|---|
char* | currency_symbol | The symbol used for currency in the current C locale. |
char | frac_digits | The number of digits after the decimal point to display in a monetary quantity. |
char | p_cs_precedes | 1 if currency_symbol is placed before non-negative value, 0 if after. |
char | n_cs_precedes | 1 if currency_symbol is placed before negative value, 0 if after. |
char | p_sep_by_space | Indicates the separation of currency_symbol, positive_sign, and the non-negative monetary value. |
char | n_sep_by_space | Indicates the separation of currency_symbol, negative_sign, and the negative monetary value. |
char | p_sign_posn | Indicates the position of positive_sign in a non-negative monetary value. |
char | n_sign_posn | Indicates the position of negative_sign in a negative monetary value. |
Local monetary numeric formatting members
Type | Member | Description |
---|---|---|
char* | int_curr_symbol | The string used as international currency name in the current C locale. |
char | int_frac_digits | The number of digits after the decimal point to display in an international monetary quantity. |
char | int_p_cs_precedes | 1 if int_curr_symbol is placed before non-negative international monetary value, 0 if after. |
char | int_n_cs_precedes | 1 if int_curr_symbol is placed before negative international monetary value, 0 if after. |
char | int_p_sep_by_space | Indicates the separation of int_curr_symbol, positive_sign, and the non-negative international monetary value. |
char | int_n_sep_by_space | Indicates the separation of int_curr_symbol, negative_sign, and the negative international monetary value. |
char | int_p_sign_posn | Indicates the position of positive_sign in a non-negative international monetary value. |
char | int_n_sign_posn | Indicates the position of negative_sign in a negative international monetary value. |
The characters of the C-strings pointed to by grouping and mon_grouping are interpreted according to their numeric values. When the terminating '\0' is encountered, the last value seen is assumed to repeat for the remainder of digits. If CHAR_MAX is encountered, no further digits are grouped. the typical grouping of three digits at a time is "\003".
The values of p_sep_by_space, n_sep_by_space, int_p_sep_by_space, int_n_sep_by_space are interpreted as follows:
- 0 - no space separates the currency symbol and the value
- 1 - sign sticks to the currency symbol, value is separated by a space
- 2 - sign sticks to the value. Currency symbol is separated by a space
The values of p_sign_posn, n_sign_posn, int_p_sign_posn, int_n_sign_posn are interpreted as follows:
- 0 - parentheses around the value and the currency symbol are used to represent the sign
- 1 - sign before the value and the currency symbol
- 2 - sign after the value and the currency symbol
- 3 - sign before the currency symbol
- 4 - sign after the currency symbol
Example:
The example below shows the usage of lconv type.
#include <stdio.h> #include <locale.h> int main (){ setlocale (LC_MONETARY,"en_US.UTF-8"); struct lconv *lc = localeconv(); printf("Local Currency Symbol: %s\n", lc->currency_symbol); printf("International Currency Symbol: %s\n", lc->int_curr_symbol); return 0; }
The output of the above code will be:
Local Currency Symbol: $ International Currency Symbol: USD
❮ C <locale.h> Library