hier:lexical_cast strtof strtold Genauigkeit verlieren?
#include <iostream>
#include <cstdlib>
#include <boost/lexical_cast.hpp>
int main(void) {
const char * str = "277499.84";
std::cout << boost::lexical_cast<double>(str) << std::endl;
std::cout << strtof(str, NULL) << std::endl;
std::cout << strtold(str, NULL) << std::endl;
std::cout << atof(str) << std::endl;
return 0;
}
Ausgang:
277500
277500
277500
277500
Warum die Ausgabe nicht 277.499,84?
Die Standardpräzision ist 6 Ich nehme an, genau wie für 'printf''% f'. Ändern Sie es, wenn Sie es nicht mögen. –