C Standard Library - <locale.h>
Introduction
locale.h The header file defines locale-specific settings, such as date format and currency symbol. Next we will introduce some macros, as well as an important structure struct lconv and two important functions.
Library macros
The macros defined in the header file locale.h are listed below. These macros will be used in the following two functions:
Serial Number | Macro & Description |
---|---|
1 | LC_ALL Set all options below. |
2 | LC_COLLATE Affects the strcoll and strxfrm functions. |
3 | LC_CTYPE Affects all character functions. |
4 | LC_MONETARY Influences the currency information provided by the localeconv function. |
5 | LC_NUMERIC Affects decimal point formatting and information provided by the localeconv function. |
6 | LC_TIME Affects the strftime function. |
Library functions
The functions defined in the header file locale.h are listed below:
Serial number | Function & Description |
---|---|
1 | char *setlocale(int category, const char *locale) Set or read Regionalized information. |
2 | struct lconv *localeconv(void) Set or read localization information. |
Library structure
typedef struct { 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;} lconv
The following is the description of each field:
Serial number | Field & Description |
---|---|
1 | decimal_point The decimal point character used for non-monetary values. |
2 | thousands_sep Thousands separator for non-monetary values. |
3 | grouping A string representing the size of each group of numbers in a non-monetary quantity. Each character represents an integer value, and each integer specifies the number of bits in the current group. A value of 0 means that the previous value will be applied to the remaining groupings. |
4 | int_curr_symbol The string used for the international currency symbol. The first three characters are specified by ISO 4217:1987, and the fourth character separates the currency symbol and currency amount. |
5 | currency_symbol The local symbol used for the currency. |
6 | mon_decimal_point The decimal point character used for currency values. |
7 | mon_thousands_sep Thousands separator used for monetary values. |
8 | mon_grouping A string representing the size of each group of numbers in the monetary value. Each character represents an integer value, and each integer specifies the number of bits in the current group. A value of 0 means that the previous value will be applied to the remaining groupings. |
9 | positive_sign The character used for positive monetary values. |
10 | negative_sign The character used for negative monetary values. |
11 | int_frac_digits The number of digits to be displayed after the decimal point in international currency values. |
12 | frac_digits The number of digits to be displayed after the decimal point in currency values. |
13 | p_cs_precedes If equal to 1, currency_symbol appears before the positive currency value. If equal to 0, currency_symbol appears after a positive currency value. |
14 | p_sep_by_space If equal to 1, currency_symbol and the positive currency value are separated by a space. If equal to 0, no space is used between currency_symbol and the positive currency value. |
15 | n_cs_precedes If equal to 1, currency_symbol appears before negative currency values. If equal to 0, currency_symbol appears after negative currency values. |
16 | n_sep_by_space If equal to 1, currency_symbol and negative currency values are separated by a space. If equal to 0, no space is used between currency_symbol and negative currency values. |
17 | p_sign_posn represents the position of the positive sign in a positive currency value. |
18 | n_sign_posn Represents the position of the negative sign in a negative currency value. |
The following values are used for p_sign_posn and n_sign_posn:
Description | |
---|---|
Parents that encapsulate the value and currency_symbol. | |
The symbol placed before the value and currency_symbol. | |
The symbol placed after the value and currency_symbol. | |
The symbol placed immediately before the value and currency_symbol. | |
The symbol placed immediately after the value and currency_symbol. |