Set numeric formatting according to the current locale
Synopsis:
#include <locale.h>
struct lconv * localeconv( void );
Library:
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
Description:
The localeconv() function gets the values appropriate for
formatting numeric quantities using the current locale.
It returns a pointer to a struct lconv
with the following members:
- char * decimal_point
- The decimal-point character used for nonmonetary quantities.
- char * thousands_sep
- The character used to separate groups of digits on the left of the
decimal-point character formatted nonmonetary quantities.
- char * int_curr_symbol
- The international currency symbol for the current locale.
The first three characters contain the alphabetic international
currency symbol in accordance with those specified in
ISO 4217: Codes for the Representation of Currency and Funds.
The fourth character (immediately preceding the
NUL character) is the character used to separate the
international currency symbol from the monetary quantity.
- char * currency_symbol
- The local currency symbol applicable to the current locale.
- char * mon_decimal_point
- The decimal-point character used to format monetary quantities.
- char * mon_thousands_sep
- The character used to separate groups of digits on the left of the
decimal-point character in formatted monetary quantities.
- char * mon_grouping
- A string whose elements indicate the size of each group of digits
in formatted monetary quantities.
- char * grouping
- A string whose elements indicate the size of each group of digits
in formatted nonmonetary quantities.
- char * positive_sign
- The string used to indicate a nonnegative monetary quantity.
- char * negative_sign
- The string used to indicate a negative monetary quantity.
- char int_frac_digits
- The number of fractional digits (to the right of the decimal
point) to display in an internationally formatted monetary quantity.
- char frac_digits
- The number of fractional digits (to the right of the decimal
point) to display in a formatted monetary quantity.
- char p_cs_precedes
- Set to 1 or 0 if the currency_symbol precedes or follows
the value for a nonnegative monetary quantity.
- char p_sep_by_space
- Set to 1 or 0 if the currency_symbol
is or isn't separated by a space from the value for a nonnegative
monetary quantity.
- char n_cs_precedes
- Set to 1 or 0 if the
currency_symbol precedes
or follows the value for a negative monetary quantity.
- char n_sep_by_space
- Set to 1 or 0 if the currency_symbol
is or isn't separated by a space from the value for a negative monetary quantity.
- char p_sign_posn
- The position of the positive_sign for a nonnegative monetary quantity.
- char n_sign_posn
- The position of the positive_sign for a negative monetary quantity.
The grouping and mon_grouping members
have the following values:
- CHAR_MAX
- Perform no further grouping.
- 0
- Repeat the previous element used for the remainder of the digits.
- other
- The value is the number of digits that comprise the current group.
Examine the next element to determine the size of the next group
of digits (to the left of the current group).
The p_sign_posn and n_sign_posn members have the
following values:
- 0
- Parentheses surround the quantity and currency_symbol.
- 1
- The sign string precedes the quantity and currency_symbol.
- 2
- The sign string follows the quantity and currency_symbol.
- 3
- The sign string immediately precedes the quantity and currency_symbol.
- 4
- The sign string immediately follows the quantity and currency_symbol.
Note:
QNX Neutrino provides this function for POSIX compatibility, but it isn't adequate for internationalization.
QNX Neutrino ships
the International Components for Unicode (ICU) libraries (
libicu*) that you can use
instead. For more information about ICU, see
https://icu.unicode.org/home.
Returns:
A pointer to the struct lconv.
Examples:
#include <stdio.h>
#include <locale.h>
#include <stdlib.h>
int main( void )
{
struct lconv *lc;
lc = localeconv();
printf( "decimal_point (%s)\n", lc->decimal_point );
printf( "thousands_sep (%s)\n", lc->thousands_sep );
printf( "int_curr_symbol (%s)\n", lc->int_curr_symbol );
printf( "currency_symbol (%s)\n", lc->currency_symbol );
printf( "mon_decimal_point (%s)\n", lc->mon_decimal_point );
printf( "mon_thousands_sep (%s)\n", lc->mon_thousands_sep );
printf( "mon_grouping (%s)\n", lc->mon_grouping );
printf( "grouping (%s)\n", lc->grouping );
printf( "positive_sign (%s)\n", lc->positive_sign );
printf( "negative_sign (%s)\n", lc->negative_sign );
printf( "int_frac_digits (%d)\n", lc->int_frac_digits );
printf( "frac_digits (%d)\n", lc->frac_digits );
printf( "p_cs_precedes (%d)\n", lc->p_cs_precedes );
printf( "p_sep_by_space (%d)\n", lc->p_sep_by_space );
printf( "n_cs_precedes (%d)\n", lc->n_cs_precedes );
printf( "n_sep_by_space (%d)\n", lc->n_sep_by_space );
printf( "p_sign_posn (%d)\n", lc->p_sign_posn );
printf( "n_sign_posn (%d)\n", lc->n_sign_posn );
return EXIT_SUCCESS;
}
Classification:
ANSI,
POSIX 1003.1
Safety: |
|
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |