LOCALECONV(3P)

๐Ÿ’– LOCALECONV ๐Ÿ’–

okay bestie, welcome to localeconv(3P) โ€” this is the POSIX Programmer's Manual page for it, and it's giving "let me tell you what your locale is doing with numbers" energy. โœจ


๐ŸŒธ PROLOG ๐ŸŒธ

okay so first things first, this manual page is part of the POSIX Programmer's Manual. Heads up tho: the Linux implementation of this interface may differ โ€” so if you're on Linux, go check the corresponding Linux manual page for the actual details of how Linux does it. Also possible: the interface just isn't implemented on Linux at all. ๐Ÿ˜ญ So like, vibe check your platform first, iykyk.


๐ŸŽ€ NAME ๐ŸŽ€

localeconv โ€” return locale-specific information. yes queen, that's literally the whole job. ๐Ÿ’…


โœจ SYNOPSIS โœจ

#include <locale.h>

struct lconv *localeconv(void);

that's it. no arguments. she takes nothing and gives you everything (about locale formatting). ๐Ÿซถ


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

ngl bestie, the functionality described on this reference page is aligned with the ISO C standard. So if there's any conflict between the requirements described here and the ISO C standard โ€” that's unintentional, fr fr. This volume of POSIX.1โ€2017 defers to the ISO C standard. periodt.

The localeconv() function shall set the components of an object with the type struct lconv with the values appropriate for the formatting of numeric quantities (monetary and otherwise) according to the rules of the current locale. โœจ

The members of the structure with type char * are pointers to strings, and any of which (except decimal_point) can point to "", to indicate that the value is not available in the current locale or is of zero length. The members with type char are non-negative numbers, and any of which can be {CHAR_MAX} to indicate that the value is not available in the current locale.

The members include the following:

  • char *decimal_point โ€” The radix character used to format non-monetary quantities.
  • char *thousands_sep โ€” The character used to separate groups of digits before the decimal-point character in formatted non-monetary quantities.
  • char *grouping โ€” A string whose elements taken as one-byte integer values indicate the size of each group of digits in formatted non-monetary quantities.
  • char *int_curr_symbol โ€” The international currency symbol applicable to the current locale. The first three characters contain the alphabetic international currency symbol in accordance with those specified in the ISO 4217:2001 standard. The fourth character (immediately preceding the null byte) 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 radix character used to format monetary quantities.
  • char *mon_thousands_sep โ€” The separator for groups of digits before the decimal-point in formatted monetary quantities.
  • char *mon_grouping โ€” A string whose elements taken as one-byte integer values indicate the size of each group of digits in formatted monetary quantities.
  • char *positive_sign โ€” The string used to indicate a non-negative valued formatted monetary quantity.
  • char *negative_sign โ€” The string used to indicate a negative valued formatted monetary quantity.
  • char int_frac_digits โ€” The number of fractional digits (those after the decimal-point) to be displayed in an internationally formatted monetary quantity.
  • char frac_digits โ€” The number of fractional digits (those after the decimal-point) to be displayed in a formatted monetary quantity.
  • char p_cs_precedes โ€” Set to 1 if the currency_symbol precedes the value for a non-negative formatted monetary quantity. Set to 0 if the symbol succeeds the value.
  • char p_sep_by_space โ€” Set to a value indicating the separation of the currency_symbol, the sign string, and the value for a non-negative formatted monetary quantity.
  • char n_cs_precedes โ€” Set to 1 if the currency_symbol precedes the value for a negative formatted monetary quantity. Set to 0 if the symbol succeeds the value.
  • char n_sep_by_space โ€” Set to a value indicating the separation of the currency_symbol, the sign string, and the value for a negative formatted monetary quantity.
  • char p_sign_posn โ€” Set to a value indicating the positioning of the positive_sign for a non-negative formatted monetary quantity.
  • char n_sign_posn โ€” Set to a value indicating the positioning of the negative_sign for a negative formatted monetary quantity.
  • char int_p_cs_precedes โ€” Set to 1 or 0 if the int_curr_symbol respectively precedes or succeeds the value for a non-negative internationally formatted monetary quantity.
  • char int_n_cs_precedes โ€” Set to 1 or 0 if the int_curr_symbol respectively precedes or succeeds the value for a negative internationally formatted monetary quantity.
  • char int_p_sep_by_space โ€” Set to a value indicating the separation of the int_curr_symbol, the sign string, and the value for a non-negative internationally formatted monetary quantity.
  • char int_n_sep_by_space โ€” Set to a value indicating the separation of the int_curr_symbol, the sign string, and the value for a negative internationally formatted monetary quantity.
  • char int_p_sign_posn โ€” Set to a value indicating the positioning of the positive_sign for a non-negative internationally formatted monetary quantity.
  • char int_n_sign_posn โ€” Set to a value indicating the positioning of the negative_sign for a negative internationally formatted monetary quantity.

The elements of grouping and mon_grouping are interpreted according to the following:

  • {CHAR_MAX} โ€” No further grouping is to be performed.
  • 0 โ€” The previous element is to be repeatedly used for the remainder of the digits.
  • other โ€” The integer value is the number of digits that comprise the current group. The next element is examined to determine the size of the next group of digits before the current group.

The values of p_sep_by_space, n_sep_by_space, int_p_sep_by_space, and int_n_sep_by_space are interpreted according to the following:

  • 0 โ€” No space separates the currency symbol and value.
  • 1 โ€” If the currency symbol and sign string are adjacent, a space separates them from the value; otherwise, a space separates the currency symbol from the value.
  • 2 โ€” If the currency symbol and sign string are adjacent, a space separates them; otherwise, a space separates the sign string from the value.

For int_p_sep_by_space and int_n_sep_by_space, the fourth character of int_curr_symbol is used instead of a space. ๐Ÿ‘€

The values of p_sign_posn, n_sign_posn, int_p_sign_posn, and int_n_sign_posn are interpreted according to the following:

  • 0 โ€” Parentheses surround the quantity and currency_symbol or int_curr_symbol.
  • 1 โ€” The sign string precedes the quantity and currency_symbol or int_curr_symbol.
  • 2 โ€” The sign string succeeds the quantity and currency_symbol or int_curr_symbol.
  • 3 โ€” The sign string immediately precedes the currency_symbol or int_curr_symbol.
  • 4 โ€” The sign string immediately succeeds the currency_symbol or int_curr_symbol.

The implementation shall behave as if no function in this volume of POSIX.1โ€2017 calls localeconv().

๐Ÿšจ bestie important note: the localeconv() function need not be thread-safe. not me being a little chaotic about threads, but there it is. ๐Ÿ’€

๐Ÿ’… RETURN VALUE ๐Ÿ’…

The localeconv() function shall return a pointer to the filled-in object. ๐ŸŽ€

The application shall not modify the structure to which the return value points, nor any storage areas pointed to by pointers within the structure. Like, hands off, okay? ๐Ÿ™ˆ

The returned pointer, and pointers within the structure, might be invalidated or the structure or the storage areas might be overwritten by a subsequent call to localeconv(). In addition, the returned pointer, and pointers within the structure, might be invalidated or the structure or the storage areas might be overwritten by subsequent calls to setlocale() with the categories LC_ALL, LC_MONETARY, or LC_NUMERIC, or by calls to uselocale() which change the categories LC_MONETARY or LC_NUMERIC. The returned pointer, pointers within the structure, the structure, and the storage areas might also be invalidated if the calling thread is terminated. ๐Ÿ˜ญ

fr fr: don't hold onto that pointer like it's forever. it's giving "situationship," not "soulmate." ๐Ÿ’”

โญ ERRORS โญ

No errors are defined. iconic behavior honestly, she simply doesn't fail. โœจ

The following sections are informative.


๐ŸŒˆ EXAMPLES ๐ŸŒˆ

None.


okay bestie that's where part 1 wraps up โ€” more parts coming, don't go anywhere ๐Ÿซถ

๐Ÿ’ธ APPLICATION USAGE ๐Ÿ’ธ

okay bestie, this is the part where it all clicks into place โœจ. Here's a lil illustration of the rules that four countries might use to format monetary quantities ๐Ÿ‘‡

  • Italy โ€” positive format โ‚ฌ.1.230, negative format -โ‚ฌ.1.230, international format EUR.1.230
  • Netherlands โ€” positive format โ‚ฌ 1.234,56, negative format โ‚ฌ -1.234,56, international format EUR 1.234,56
  • Norway โ€” positive format kr1.234,56, negative format kr1.234,56-, international format NOK 1.234,56
  • Switzerland โ€” positive format SFrs.1,234.56, negative format SFrs.1,234.56C, international format CHF 1,234.56

and for these same four countries, the monetary members of the struct that localeconv() hands back to you are exactly this ๐Ÿซถ

  • int_curr_symbol โ€” Italy "EUR.", Netherlands "EUR ", Norway "NOK ", Switzerland "CHF " (yep, those trailing spaces are real, no cap, don't @ me)
  • currency_symbol โ€” Italy "โ‚ฌ.", Netherlands "โ‚ฌ", Norway "kr", Switzerland "SFrs."
  • mon_decimal_point โ€” Italy "", Netherlands ",", Norway ",", Switzerland "."
  • mon_thousands_sep โ€” Italy ".", Netherlands ".", Norway ".", Switzerland ","
  • mon_grouping โ€” Italy "\3", Netherlands "\3", Norway "\3", Switzerland "\3"
  • positive_sign โ€” Italy "", Netherlands "", Norway "", Switzerland ""
  • negative_sign โ€” Italy "-", Netherlands "-", Norway "-", Switzerland "C"
  • int_frac_digits โ€” Italy 0, Netherlands 2, Norway 2, Switzerland 2
  • frac_digits โ€” Italy 0, Netherlands 2, Norway 2, Switzerland 2
  • p_cs_precedes โ€” Italy 1, Netherlands 1, Norway 1, Switzerland 1
  • p_sep_by_space โ€” Italy 0, Netherlands 1, Norway 0, Switzerland 0
  • n_cs_precedes โ€” Italy 1, Netherlands 1, Norway 1, Switzerland 1
  • n_sep_by_space โ€” Italy 0, Netherlands 1, Norway 0, Switzerland 0
  • p_sign_posn โ€” Italy 1, Netherlands 1, Norway 1, Switzerland 1
  • n_sign_posn โ€” Italy 1, Netherlands 4, Norway 2, Switzerland 2
  • int_p_cs_precedes โ€” Italy 1, Netherlands 1, Norway 1, Switzerland 1
  • int_n_cs_precedes โ€” Italy 1, Netherlands 1, Norway 1, Switzerland 1
  • int_p_sep_by_space โ€” Italy 0, Netherlands 0, Norway 0, Switzerland 0
  • int_n_sep_by_space โ€” Italy 0, Netherlands 0, Norway 0, Switzerland 0
  • int_p_sign_posn โ€” Italy 1, Netherlands 1, Norway 1, Switzerland 1
  • int_n_sign_posn โ€” Italy 1, Netherlands 4, Norway 4, Switzerland 2

๐Ÿค” RATIONALE ๐Ÿค”

None.

like... none. that's the whole rationale. the reasoning is simply that there isn't one. iconic behaviour honestly ๐Ÿ’…


๐Ÿ”ฎ FUTURE DIRECTIONS ๐Ÿ”ฎ

None.

also none bestie, the future is a mystery and this page is not about to speculate ๐ŸŒธ


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

go read these too, they're all part of the same friend group fr fr:

  • fprintf()
  • fscanf()
  • isalpha()
  • isascii()
  • nl_langinfo()
  • setlocale()
  • strcat()
  • strchr()
  • strcmp()
  • strcoll()
  • strcpy()
  • strftime()
  • strlen()
  • strpbrk()
  • strspn()
  • strtok()
  • strxfrm()
  • strtod()
  • uselocale()

and also, from the Base Definitions volume of POSIX.1โ€2017:

  • <langinfo.h>
  • <locale.h>

Some of this text has been reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. ๐Ÿ’œ

heads up bestie: if this version and the original IEEE and The Open Group Standard ever disagree about something, the original is the referee document. that's the final boss, no arguments. You can get the original Standard online at http://www.opengroup.org/unix/online.html .

And any typographical or formatting errors you spot on this page were most likely introduced during the conversion of the source files into man page format ๐Ÿ™ˆ. To report errors like that, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .


and that's the whole page, bestie!! brought to you by IEEE/The Open Group, dated 2017, living under the name LOCALECONV(3P) ๐Ÿ’–โœจ go format some currency and slay ๐ŸŽ€๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from