std::moneyp...ative_sign,(3)
π std::moneypunct::positive_sign, do_positive_sign, negative_sign π
okay bestie, we are so in the C++ Standard Libary right now β yes, that's the manual name from the header, spelling included, no notes π
This page is the money-sign corner of std::moneypunct, and it is lowkey iconic.
β¨ NAME β¨
std::moneypunct::positive_sign,do_positive_sign,negative_sign,β the full name blob, trailing comma and all. The source also repeatsstd::moneypunct::positive_sign,do_positive_sign,negative_sign,after the dash, so we're keeping both copies, periodt π«Ά
πΈ Synopsis πΈ
Defined in header <locale>.
public: (1)
string_type positive_sign() const;
public: (2)
string_type negative_sign() const;
protected: (3)
virtual string_type do_positive_sign() const;
protected: (4)
virtual string_type do_negative_sign() const;
1)Public member function, calls the member functiondo_positive_signof the most derived class.2)Public member function, calls the member functiondo_negative_signof the most derived class.3)Returns the string that is used for formatting of positive monetary values.3)Returns the string that is used for formatting of negative monetary values. (not me fixing the source's double3)β I would never π)
Only the first character of the string returned is the character that appears in the pos_format()/neg_format() position indicated by the value sign. The rest of the characters appear after the rest of the monetary string. So like, first char gets the sign slot, the leftovers trail after the money string β that's the rule β¨
In particular, for negative_sign of "-", the formatting may appear as "-1.23 β¬", while for negative_sign of "()" it would appear as "(1.23 β¬)".
π Return value π
The string of type string_type holding the characters to be used as positive or negative sign. That's the whole return value, bestie π
π§ͺ Example π§ͺ
// Run this code
#include <iomanip>
#include <iostream>
#include <locale>
struct my_punct : std::moneypunct_byname<char, false>
{
my_punct(const char* name) : moneypunct_byname(name) {}
string_type do_negative_sign() const { return "()"; }
};
int main()
{
std::locale loc("de_DE.utf8");
std::cout.imbue(loc);
std::cout << loc.name() << " negative sign is '"
<<
std::use_facet<std::moneypunct<char>>(loc).negative_sign()
<< "' for example: " << std::showbase <<
std::put_money(-1234) << '\n';
std::locale loc2("ms_MY.utf8");
std::cout.imbue(loc2);
std::cout << loc2.name() << " negative sign is '"
<<
std::use_facet<std::moneypunct<char>>(loc2).negative_sign()
<< "' for example: " << std::put_money(-1234) << '\n';
std::cout.imbue(std::locale(std::cout.getloc(), new
my_punct("de_DE.utf8")));
std::cout << "de_DE.utf8 with negative_sign set to \"()\": "
<< std::put_money(-1234) << '\n';
}
Output:
de_DE.utf8 negative sign is '-' for example: -12,34 β¬
ms_MY.utf8 negative sign is '()' for example: (RM12.34)
de_DE.utf8 with negative_sign set to "()": (12,34 β¬)
π See also π
do_pos_formatprovides the formatting pattern for currency valuesdo_neg_format(virtual protected member function) β[virtual]
okay bye bestie! π source/version: http://cppreference.com Β· date: 2024.06.10 Β· footer title: std::moneyp...ative_sign,(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