std::lconv(3)
π NAME π
std::lconv β bestie, it's std::lconv. That's it. That's the name. (We're in the C++ Standard Library, section 3, and yes I will be making this whole thing cute, no cap.)
β¨ SYNOPSIS β¨
Defined in header <clocale>:
struct lconv;
Okay so picture this: std::lconv is literally the struct that holds all your numeric and monetary formatting rules, exactly as defined by a C locale. That's its whole job and it does it slayfully. πΈ
You don't just make one yourself, though β objects of this struct may be obtained with std::localeconv. Rude of it to be gatekept but okay.
So the members of std::lconv are values of type char and values of type char*. And here's the little detail everyone forgets: each char* member except decimal_point may be pointing at a null character (that is, at an empty C-string). Yeah. Empty. Don't assume you got a real string, queen. π
And the members of type char are all non-negative numbers, any of which may be CHAR_MAX if the corresponding value is not available in the current C locale. So if you see CHAR_MAX bestie, that's not a number, that's a "we don't have this, sorry." π
π MEMBER OBJECTS π
π Non-monetary numeric formatting parameters
char* decimal_pointβ the character used as the decimal point (public member object)char* thousands_sepβ the character used to separate groups of digits before the decimal point (public member object)char* groupingβ a string whose elements indicate the sizes of digit groups (public member object)
π§ Monetary numeric formatting parameters
char* mon_decimal_pointβ the character used as the decimal point (public member object)char* mon_thousands_sepβ the character used to separate groups of digits before the decimal point (public member object)char* mon_groupingβ a string whose elements indicate the sizes of digit groups (public member object)char* positive_signβ a string used to indicate non-negative monetary quantity (public member object)char* negative_signβ a string used to indicate negative monetary quantity (public member object)
π Local monetary numeric formatting parameters
char* currency_symbolβ the symbol used for currency in the current C locale (public member object)char frac_digitsβ the number of digits after the decimal point to display in a monetary quantity (public member object)char p_cs_precedesβ 1 ifcurrency_symbolis placed before non-negative value, 0 if after (public member object)char n_cs_precedesβ 1 ifcurrency_symbolis placed before negative value, 0 if after (public member object)char p_sep_by_spaceβ indicates the separation ofcurrency_symbol,positive_sign, and the non-negative monetary value (public member object)char n_sep_by_spaceβ indicates the separation ofcurrency_symbol,negative_sign, and the negative monetary value (public member object)char p_sign_posnβ indicates the position ofpositive_signin a non-negative monetary value (public member object)char n_sign_posnβ indicates the position ofnegative_signin a negative monetary value (public member object)
π International monetary numeric formatting parameters
char* int_curr_symbolβ the string used as international currency name in the current C locale (public member object)char int_frac_digitsβ the number of digits after the decimal point to display in an international monetary quantity (public member object)char int_p_cs_precedes(C++11) β 1 ifint_curr_symbolis placed before non-negative international monetary value, 0 if after (public member object)char int_n_cs_precedes(C++11) β 1 ifint_curr_symbollis placed before negative international monetary value, 0 if after (public member object)char int_p_sep_by_space(C++11) β indicates the separation ofint_curr_symbol,positive_sign, and the non-negative international monetary value (public member object)char int_n_sep_by_space(C++11) β indicates the separation ofint_curr_symbol,negative_sign, and the negative international monetary value (public member object)char int_p_sign_posn(C++11) β indicates the position ofpositive_signin a non-negative international monetary value (public member object)char int_n_sign_posn(C++11) β indicates the position ofnegative_signin a negative international monetary value (public member object)
Not me pointing out thatint_curr_symbollup there really does have an extralin the original. That's how it's written, bestie, I don't make the rules. π«Ά
π¦ how do grouping and mon_grouping actually work
So the characters of the C-strings pointed to by grouping and mon_grouping are interpreted according to their numeric values. Read the characters as numbers, not as letters, iykyk.
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.
And the typical grouping of three digits at a time is "\003". Cute, right? Told you. β¨
π§ how *_sep_by_space is interpreted
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 value1β sign sticks to the currency symbol, value is separated by a space2β sign sticks to the value. Currency symbol is separated by a space
π how *_sign_posn is interpreted
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 sign1β sign before the value and the currency symbol2β sign after the value and the currency symbol3β sign before the currency symbol4β sign after the currency symbol
π₯ EXAMPLE π₯
// Run this code
#include <clocale>
#include <iostream>
int main()
{
std::setlocale(LC_ALL, "ja_JP.UTF-8");
std::lconv* lc = std::localeconv();
std::cout << "Japanese currency symbol: " << lc->currency_symbol
<< '(' << lc->int_curr_symbol << ")\n";
}
β Output
Japanese currency symbol: οΏ₯(JPY )
Look at that output. It ate. π
π¦ SEE ALSO π¦
localeconvβ queries numeric and monetary formatting details of the current locale (function)numpunctβ defines numeric punctuation rules (class template)moneypunctβ defines monetary formatting parameters used bystd::money_getandstd::money_put(class template)- C documentation for
lconv
Okay that's the whole page, you're welcome, go format some money correctly. π This masterpiece was served to you fresh from cppreference.com, dated 2024.06.10, and it goes by std::lconv(3). Mwah. π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms