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

do_frac_digits

Defined in header <locale>

?

?

public: int frac_digits() const;

(1)

?

protected: virtual int do_frac_digits() const;

(2)

?

1%29公共成员函数,调用成员函数do_frac_digits最派生的类。

2%29在打印货币值时返回小数点后要显示的数字数。

返回值

小数点之后要显示的数字数。在常见的美国地区,这是2...

二次

代码语言:javascript
复制
#include <locale>
#include <iostream>
#include <iomanip>
#include <iterator>
struct space_out : std::moneypunct<char> {
    pattern do_pos_format()      const { return { {value, none, none, none} };}
    int do_frac_digits()         const { return 0; }
    char_type do_thousands_sep() const { return ' ';}
    string_type do_grouping()    const { return "\002";}
};
int main()
{
    std::cout.imbue(std::locale("en_US.UTF-8"));
    std::cout << "american locale: " << std::showbase
              << std::put_money(12345678.0)<< '\n';
 
    std::cout.imbue(std::locale(std::cout.getloc(), new space_out));
    std::cout << "locale with modified moneypunct: "
              << std::put_money(12345678.0)<< '\n';
}

二次

产出:

二次

代码语言:javascript
复制
american locale: $123,456.78
locale with modified moneypunct: 12 34 56 78

二次

另见

do_thousands_sep virtual

provides the character to use as thousands separator (virtual protected member function)

do_decimal_point virtual

provides the character to use as decimal point (virtual protected member function)

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com