【问题标题】:WinGW g++ put_money iomanip gives unexpected resultMinGW c++ put money iomanip 给出了意想不到的结果
【发布时间】:2015-09-18 10:08:05
【问题描述】:

我正在尝试格式化货币,使用下面的代码作为测试。

long double mon = 1234567.45; // or std::string mon = "123.45";
std::cout.imbue(std::locale(""));
std::cout << "normal:   " << mon << std::endl;
std::cout << "formated: " << std::showbase << std::put_money(mon*100) << std::endl;

但我得到了意想不到的结果。

g++ -std=c++0x -O1 -g3 -Wall -c -fmessage-length=0 -o tst.o tst.cpp
g++ -o tst tst.o

normal:   -2.64326e-199
formated: 526296518301961010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

我在 Win10 上使用 g++ 版本 4.8.1

在我的 Ubuntu 机器上,使用版本 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04)。 我得到以下正确结果。

normal:   1,12346e+06
formated: € 1 123 456,45

发生了什么事??

【问题讨论】:

    标签: g++ iomanip


    【解决方案1】:

    经过更多研究,我发现这是 MinGW g++ 4.8.1 的错误。 这个版本不能很好的处理long double类型。

    Long Double Output Bug In MinGW

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-19
      • 2017-01-05
      • 2021-10-14
      • 1970-01-01
      • 1970-01-01
      • 2021-12-17
      • 2021-04-22
      • 2016-02-13
      相关资源
      最近更新 更多