Home > Electronics Tutorials > C Language Tutorial > locale.h - localeconv

C Language Programming Library Reference Guide

locale.h - localeconv

Declaration: struct lconv *localeconv(void); Sets the structure lconv to represent the current location settings.

The string pointers in the structure may point to a null string ("") which indicates that the value is not available. The char types are nonnegative numbers. If the value is CHAR_MAX, then the value is not available.

lconv variables:

char *decimal_point Decimal point character used for non-monetary values.
char *thousands_sep Thousands place separator character used for non-monetary values.
char *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.
char *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.
char *currency_symbol The local symbol used for currency.
char *mon_decimal_point The decimal point character used for monetary values.
char *mon_thousands_sep The thousands place grouping character used for monetary values.
char *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.
char *positive_sign The character used for positive monetary values.
char *negative_sign The character used for negative monetary values.
char int_frac_digits Number of digits to show after the decimal point in international monetary values.
char frac_digits Number of digits to show after the decimal point in monetary values.
char 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.
char 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.
char 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.
char 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.
char p_sign_posn Represents the position of the positive_sign in a positive monetary value.
char n_sign_posn Represents the position of the negative_sign in a negative monetary value.
 

The following values are used for p_sign_posn and n_sign_posn:

0 Parentheses encapsulate the value and the currency_symbol.
1 The sign precedes the value and currency_symbol.
2 The sign succeeds the value and currency_symbol.
3 The sign immediately precedes the value and currency_symbol.
4 The sign immediately succeeds the value and currency_symbol.

Example:

#include<locale.h>
#include<stdio.h>
int main(void)
{
  struct lconv locale_structure;
  struct lconv *locale_ptr=&locale_structure;

  locale_ptr=lcoaleconv();
  printf("Decimal point:                   %s",locale_ptr->decimal_point);
  printf("Thousands Separator:             %s",locale_ptr->thousands_sep);
  printf("Grouping:                        %s",locale_ptr->grouping);
  printf("International Currency Symbol:   %s",locale_ptr->int_curr_symbol);
  printf("Currency Symbol:                 %s",locale_ptr->currency_symbol);
  printf("Monetary Decimal Point:          %s",locale_ptr->mon_decimal_point);
  printf("Monetary Thousands Separator:    %s",locale_ptr->mon_thousands_sep);
  printf("Monetary Grouping:               %s",locale_ptr->mon_grouping);
  printf("Monetary Positive Sign:          %s",locale_ptr->positive_sign);
  printf("Monetary Negative Sign:          %s",locale_ptr->negative_sign);
  printf("Monetary Intl Decimal Digits:    %c",locale_ptr->int_frac_digits);
  printf("Monetary Decimal Digits:         %c",locale_ptr->frac_digits);
  printf("Monetary + Precedes:             %c",locale_ptr->p_cs_precedes);
  printf("Monetary + Space:                %c",locale_ptr->p_sep_by_space);
  printf("Monetary - Precedes:             %c",locale_ptr->n_cs_precedes);
  printf("Monetary - Space:                %c",locale_ptr->n_sep_by_space);
  printf("Monetary + Sign Posn:            %c",locale_ptr->p_sign_posn);
  printf("Monetary - Sign Posn:            %c",locale_ptr->n_sign_posn);
}
Note: To report broken links or to submit your projects, tutorials please email to Webmaster

Discover

     more......