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 NumberMacro & Description
1LC_ALL
Set all options below.
2LC_COLLATE
Affects the strcoll and strxfrm functions.
3LC_CTYPE
Affects all character functions.
4LC_MONETARY
Influences the currency information provided by the localeconv function.
5LC_NUMERIC
Affects decimal point formatting and information provided by the localeconv function.
6LC_TIME
Affects the strftime function.

Library functions

The functions defined in the header file locale.h are listed below:

Serial numberFunction & Description
1char *setlocale(int category, const char *locale)
Set or read Regionalized information.
2struct 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 numberField & Description
1decimal_point
The decimal point character used for non-monetary values.
2thousands_sep
Thousands separator for non-monetary values.
3grouping
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.
4int_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.
5currency_symbol
The local symbol used for the currency.
6mon_decimal_point
The decimal point character used for currency values.
7mon_thousands_sep
Thousands separator used for monetary values.
8mon_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.
9positive_sign
The character used for positive monetary values.
10negative_sign
The character used for negative monetary values.
11int_frac_digits
The number of digits to be displayed after the decimal point in international currency values.
12frac_digits
The number of digits to be displayed after the decimal point in currency values.
13p_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.
14p_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.
15n_cs_precedes
If equal to 1, currency_symbol appears before negative currency values. If equal to 0, currency_symbol appears after negative currency values.
16n_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.
17p_sign_posn
represents the position of the positive sign in a positive currency value.
18n_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:

##ValueDescription0Parents that encapsulate the value and currency_symbol. 1The symbol placed before the value and currency_symbol. 2The symbol placed after the value and currency_symbol. 3The symbol placed immediately before the value and currency_symbol. 4The symbol placed immediately after the value and currency_symbol.