Easy Tutorial
❮ C Function Strncpy C Function Floor ❯

C Standard Library - <locale.h>

Introduction

The locale.h header file defines locale-specific settings, such as date formats and currency symbols. Below, we will introduce some macros, an important structure struct lconv, and two key functions.

Library Macros

The following macros are defined in the locale.h header file and are used in the two functions listed below:

No. Macro & Description
1 LC_ALL <br>Sets all the below options.
2 LC_COLLATE <br>Affects the strcoll and strxfrm functions.
3 LC_CTYPE <br>Affects all character functions.
4 LC_MONETARY <br>Affects the monetary information provided by the localeconv function.
5 LC_NUMERIC <br>Affects the decimal point formatting and information provided by the localeconv function.
6 LC_TIME <br>Affects the strftime function.

Library Functions

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

No. Function & Description
1 char *setlocale(int category, const char *locale) <br>Sets or reads locale information.
2 struct lconv *localeconv(void) <br>Sets or reads locale 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 are descriptions of each field:

No. Field & Description
1 decimal_point <br>The character used for the decimal point in non-monetary values.
2 thousands_sep <br>The character used for the thousands separator in non-monetary values.
3 grouping <br>A string representing the size of each group of digits in non-monetary quantities. Each character represents an integer value, specifying the number of digits in the current group. A value of 0 means the previous value will be used for the remaining groups.
4 int_curr_symbol <br>The string used for the international currency symbol. The first three characters are specified by ISO 4217:1987, and the fourth character is used to separate the currency symbol from the monetary quantity.
5 currency_symbol <br>The local symbol used for currency.
6 mon_decimal_point <br>The character used for the decimal point in monetary values.
7 mon_thousands_sep <br>The character used for the thousands separator in monetary values.
8 mon_grouping <br>A string representing the size of each group of digits in monetary quantities. Each character represents an integer value, specifying the number of digits in the current group. A value of 0 means the previous value will be used for the remaining groups.
9 positive_sign <br>The character used for positive monetary values.
10 negative_sign <br>The character used for negative monetary values.
11 int_frac_digits <br>The number of digits to display after the decimal point in international monetary values.
12 frac_digits <br>The number of digits to display after the decimal point in monetary values.
13 p_cs_precedes <br>If equal to 1, the currency_symbol precedes a positive monetary value. If equal to 0, the currency_symbol follows a positive monetary value.
14 p_sep_by_space <br>If equal to 1, a space separates the currency_symbol from a positive monetary value. If equal to 0, no space is used between the currency_symbol and a positive monetary value.
15 n_cs_precedes <br>If equal to 1, the currency_symbol precedes a negative monetary value. If equal to 0, the currency_symbol follows a negative monetary value.
16 n_sep_by_space <br>If equal to 1, a space separates the currency_symbol from a negative monetary value. If equal to 0, no space is used between the currency_symbol and a negative monetary value.
17 p_sign_posn <br>Indicates the position of the positive sign in positive monetary values.
18 n_sign_posn <br>Indicates the position of the negative sign in negative monetary values.

The following values are used for psignposn and nsignposn:

Value Description
0 Parentheses enclose the value and currency_symbol.
1 The sign string precedes the value and currency_symbol.
2 The sign string follows the value and currency_symbol.
3 The sign string immediately precedes the value and currency_symbol.
4 The sign string immediately follows the value and currency_symbol.
❮ C Function Strncpy C Function Floor ❯