<locale.h> - C語言標準庫


locale.h標頭檔案定義了特定的位置設定,如日期格式和貨幣符號。有一個重要的結構struct lconv和兩個重要的函式,下面列出一些巨集定義。

庫巨集

以下是在檔頭中定義的巨集,這些巨集將被用在下面列出的兩個函式:

S.N. 巨集及說明
1 LC_ALL
Set everything.
2 LC_COLLATE
Affects strcoll and strxfrm functions.
3 LC_CTYPE
Affects all character functions.
4 LC_MONETARY
Affects the monetary information provided by localeconv function.
5 LC_NUMERIC
Affects decimal-yiibai formatting and the information provided by localeconv function.
6 LC_TIME
Affects the strftime function.

庫函式

以下是頭locale.h中定義的函式:

S.N. 功能及說明
1 char *setlocale(int category, const char *locale)
設定或讀取位置相關的資訊。
2 struct lconv *localeconv(void)
設定或讀取位置相關的資訊。

庫結構

typedef struct {
   char *decimal_yiibai;
   char *thousands_sep;
   char *grouping;	
   char *int_curr_symbol;
   char *currency_symbol;
   char *mon_decimal_yiibai;
   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

以下是每個欄位的描述:

S.N. 欄位&說明
1 decimal_yiibai
Decimal yiibai character used for non-monetary values.
2 thousands_sep
Thousands place separator character used for non-monetary values..
3 grouping
A string that indicates the size of each group of digits in non-monetary quantities. Each character represents an integer value which designates the number of digits in the current group. A value of 0 means that the previous value is to be used for the rest of the groups.
4 int_curr_symbol
A string of the international currency symbols used. The first three characters are those specified by ISO 4217:1987 and the fourth is the character which separates the currency symbol from the monetary quantity.
5 currency_symbol
The local symbol used for currency.
6 mon_decimal_yiibai
The decimal yiibai character used for monetary values.
7 mon_thousands_sep
The thousands place grouping character used for monetary values.
8 mon_grouping
A string whose elements define the size of the grouping of digits in monetary values. Each character represents an integer value which designates the number of digits in the current group. A value of 0 means that the previous value is to be used for the rest of the groups.
9 positive_sign
The character used for positive monetary values.
10 negative_sign
The character used for negative monetary values.
11 int_frac_digits
Number of digits to show after the decimal yiibai in international monetary values.
12 frac_digits
Number of digits to show after the decimal yiibai in monetary values.
13 p_cs_precedes
If equal to 1, then the currency_symbol appears before a positive monetary value. If equal to 0, then the currency_symbol appears after a positive monetary value.
14 p_sep_by_space
If equal to 1, then the currency_symbol is separated by a space from a positive monetary value. If equal to 0, then there is no space between the currency_symbol and a positive monetary value.
15 n_cs_precedes
If equal to 1, then the currency_symbol precedes a negative monetary value. If equal to 0, then the currency_symbol succeeds a negative monetary value.
16 n_sep_by_space
If equal to 1, then the currency_symbol is separated by a space from a negative monetary value. If equal to 0, then there is no space between the currency_symbol and a negative monetary value.
17 p_sign_posn
Represents the position of the positive_sign in a positive monetary value.
18 n_sign_posn
Represents the position of the negative_sign in a negative monetary value.

使用以下值為p_sign_posn和n_sign_posn:

描述
0 括號封裝值和CURRENCY_SYMBOL的。the currency_symbol.
1 符號之前的值和currency_symbol.
2 該標誌成功的值和currency_symbol.
3 符號立即之前的值和 currency_symbol.
4 符號立即成功的值和currency_symbol.