当使用boost::lexical_cast (我在VS2013上使用boost版本1.58 )时,我无法获得字符串中指定的精确值,即使它可以在浮点型中表示:
std::wstring t = L"91.25";
float r;
r = boost::lexical_cast<float>(t);R为91.249992 (0x42B67FFF),而不是91.250000 (0x42b68000)
先前版本的boost的行为符合预期。有没有我遗漏的精确度设置?
发布于 2016-08-03 01:12:54
事实证明,这与boost无关。这似乎是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;
}https://stackoverflow.com/questions/37995387
复制相似问题