首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

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返回用于格式化负货币值的字符串。

仅返回字符串的第一个字符是出现在pos_format()/neg_format()值指示的位置sign.其余的字符出现剩下的钱。

尤其是否定的[医]标志"-",格式可能显示为"-1.23 €",则为负数[医]标志"()"它看起来就像"(1.23 €)"...

返回值

类型的字符串string_type将字符作为正负号使用。

二次

代码语言:javascript
复制
#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';
 
}

二次

产出:

二次

代码语言:javascript
复制
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)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券