do_negative_sign
Defined in header <locale> | ? | ? |
---|---|---|
public: string_type positive_sign() const; | (1) | ? |
public: string_type negative_sign() const; | (2) | ? |
protected: virtual string_type do_positive_sign() const; | (3) | ? |
protected: virtual string_type do_negative_sign() const; | (4) | ? |
1%29¹«¹²³ÉÔ±º¯Êý£¬µ÷ÓóÉÔ±º¯Êýdo_positive_sign
×îÅÉÉúµÄÀà¡£
2%29¹«¹²³ÉÔ±º¯Êý£¬µ÷ÓóÉÔ±º¯Êýdo_negative_sign
×îÅÉÉúµÄÀà¡£
3%29·µ»ØÓÃÓÚ¸ñʽ»¯Õý»õ±ÒÖµµÄ×Ö·û´®¡£
3%29·µ»ØÓÃÓÚ¸ñʽ»¯¸º»õ±ÒÖµµÄ×Ö·û´®¡£
½ö·µ»Ø×Ö·û´®µÄµÚÒ»¸ö×Ö·ûÊdzöÏÖÔÚpos_format()
/neg_format()
ֵָʾµÄλÖÃsign
.ÆäÓàµÄ×Ö·û³öÏÖºóʣϵÄÇ®¡£
ÓÈÆäÊÇ·ñ¶¨µÄ[Ò½]±êÖ¾"-"
£¬¸ñʽ¿ÉÄÜÏÔʾΪ"-1.23 €"
£¬ÔòΪ¸ºÊý[Ò½]±êÖ¾"()"
Ëü¿´ÆðÀ´¾ÍÏñ"(1.23 €)"
...
·µ»ØÖµ
ÀàÐ͵Ä×Ö·û´®string_type
½«×Ö·û×÷ΪÕý¸ººÅʹÓá£
Àý
¶þ´Î
#include <iostream>
#include <iomanip>
#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';
}
¶þ´Î
²ú³ö£º
¶þ´Î
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 €)
¶þ´Î
Áí¼û
do_pos_formatdo_neg_format virtual | provides the formatting pattern for currency values (virtual protected member function) |
---|
? cppreference.com
ÔÚCreativeCommonsAttributionÏÂÊÚȨ-ShareAlikeδÒÆÖ²Ðí¿Év3.0¡£
±¾ÎĵµÏµÌÚѶÔÆ¿ª·¢ÕßÉçÇø³ÉÔ±¹²Í¬Î¬»¤£¬ÈçÓÐÎÊÌâÇëÁªÏµ cloudcommunity@tencent.com