C Standard Library

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

TypeMemberDescription
char*decimal_pointThe character used as the decimal point.
char*thousands_sepThe character used to separate groups of digits before the decimal point.
char*groupingA string whose elements indicate the sizes of digit groups.

Monetary numeric formatting members

TypeMemberDescription
char*mon_decimal_pointThe character used as the decimal point.
char*mon_thousands_sepThe character used to separate groups of digits before the decimal point.
char*mon_groupingA string whose elements indicate the sizes of digit groups.
char*positive_signA string used to indicate non-negative monetary quantity.
char*negative_signA string used to indicate negative monetary quantity.

Local monetary numeric formatting members

TypeMemberDescription
char*currency_symbolThe symbol used for currency in the current C locale.
charfrac_digitsThe number of digits after the decimal point to display in a monetary quantity.
charp_cs_precedes1 if currency_symbol is placed before non-negative value, 0 if after.
charn_cs_precedes1 if currency_symbol is placed before negative value, 0 if after.
charp_sep_by_spaceIndicates the separation of currency_symbol, positive_sign, and the non-negative monetary value.
charn_sep_by_spaceIndicates the separation of currency_symbol, negative_sign, and the negative monetary value.
charp_sign_posnIndicates the position of positive_sign in a non-negative monetary value.
charn_sign_posnIndicates the position of negative_sign in a negative monetary value.

Local monetary numeric formatting members

TypeMemberDescription
char*int_curr_symbolThe string used as international currency name in the current C locale.
charint_frac_digitsThe number of digits after the decimal point to display in an international monetary quantity.
charint_p_cs_precedes1 if int_curr_symbol is placed before non-negative international monetary value, 0 if after.
charint_n_cs_precedes1 if int_curr_symbol is placed before negative international monetary value, 0 if after.
charint_p_sep_by_spaceIndicates the separation of int_curr_symbol, positive_sign, and the non-negative international monetary value.
charint_n_sep_by_spaceIndicates the separation of int_curr_symbol, negative_sign, and the negative international monetary value.
charint_p_sign_posnIndicates the position of positive_sign in a non-negative international monetary value.
charint_n_sign_posnIndicates 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