首页 文章

提升区域设置格式百分比

提问于
浏览
0

我有一个问题与boost :: locale :: format输出百分比 . 根据文件(http://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/localized_text_formatting.html):

数字和数字操纵器以下是数字格式的操纵器:as :: number - 根据当地规范的格式编号,它考虑在内
as :: percent - 格式编号为“percent”格式 . 例如:

cout << as :: percent << 0.25 << endl;

会创建一个看起来像这样的输出:

25%

但是,以下输出“0.25”:

#include <string>
#include <iostream>
#include <boost/system/system_error.hpp>
#include <boost/locale.hpp>


int main(int argc, char** argv)
{
    std::cout << boost::locale::as::percent << 0.25 <<std::endl;
}

我已经尝试通过std :: locale()以及由boost :: locale :: generator生成的语言环境来为std :: cout添加EN-US语言环境,但无济于事 .

好像我错过了一些明显的问题;有人可以提示吗?

2 回答

  • 0

    这对我有用:

    #include <boost/locale.hpp>
    #include <iostream>
    
    int main()
    {
      boost::locale::generator gen;
      std::locale loc = gen("en_US.UTF-8");
      std::cout.imbue(loc);
      std::cout << boost::locale::as::percent << 0.25 << std::endl;
      return 0;
    }
    
  • 4

    Boost.Locale使用4个后端(ICU,posix,winapi,std),但只有ICU后端具有百分比功能,这意味着您使用的库不是使用ICU库编译的 .

    您可以在Supported Features表中查看哪个功能可以与哪个后端一起使用 .

相关问题