Thus, it will probably be a restriction / error of the parser of type "float". Try using the double_ parser.
#include<iostream> #include<iomanip> #include<string> #include<boost/spirit/include/qi.hpp> int main() { std::cout.precision(20); //float x=219721.03839999999f; //std::cout << x*1.0f << std::endl; //gives 219721.03125 double resultD; std::string arg="219721.03839999999"; auto itBeg = arg.begin(); auto itEnd = arg.end(); if(!boost::spirit::qi::parse(itBeg, itEnd,boost::spirit::qi::double_,resultD) || itBeg != itEnd) std::cerr << "Cannot convert from std::string to double" << std::endl; else std::cout << "qi::double_:" << resultD << std::endl; float resultF; itBeg = arg.begin(); itEnd = arg.end(); if(!boost::spirit::qi::parse(itBeg, itEnd,boost::spirit::qi::float_,resultF) || itBeg != itEnd) std::cerr << "Cannot convert from std::string to float" << std::endl; else std::cout << "qi::float_ :" << resultF << std::endl; return 0; }
Output:
Qi :: double_: 219721,03839999999036
qi :: float_: 219721.109375
source share