Why does the following code give me different results when I write "2.01" and "2.02" ?
#include <boost/lexical_cast.hpp> #include <iostream> #include <string> int main() { const std::string str = "2.02"; try { const double b = boost::lexical_cast<double>(str) * 100.0; std::cout << "double: " << b << '\n'; const int a = boost::lexical_cast<int>(b); std::cout << "int: " << a << '\n'; } catch (const std::exception& ex) { std::cerr << ex.what() << '\n'; } }
Exit
double: 202 int: 202
But if I change "2.02" to "2.01" , it gives me the following result:
double: 201 bad lexical cast: source type value could not be interpreted as target
Why?
I am using Visual Studio 2013 (msvc-12.0) and increasing 1.57.
Thanks in advance.
source share