4

boost::lexical_cast を使用する場合 (私は VS2013 でブースト バージョン 1.58 を使用しています)、文字列で指定された正確な値を取得できません。

std::wstring t = L"91.25";
float r;
r = boost::lexical_cast<float>(t);

r は 91.250000 (0x42b68000) ではなく 91.249992 (0x42B67FFF) です

ブーストの以前のバージョンは、期待どおりに動作しました。不足している精度設定はありますか?

4

1 に答える 1

2

これはブーストとは無関係であることがわかりました。Visual Studio と VS2013 のみの問題のようです。

#include <iostream>
#include <sstream>
#include <iomanip>
int main()
{
    float a;
    std::stringstream s;
    s.str("91.25");
    s >> a;
    std::wcout << std::setprecision(20) << a << std::endl;
    // displays "91.249992370605469" when compiled with 
    // VS2013 and "91.25" when compiled with VS2010 or VS2015
    return 0;
}
于 2016-08-02T17:12:54.090 に答える