Skip to content

Instantly share code, notes, and snippets.

@bastih
Created March 6, 2014 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastih/9391405 to your computer and use it in GitHub Desktop.
Save bastih/9391405 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <sstream>
int main()
{
std::string number = "111111111.2";
std::cout << std::setprecision(20) << atof(number.c_str()) << std::endl; // double: 111111111.20000000298
std::stringstream ss;
ss << number;
float val;
ss >> val;
std::cout << std::setprecision(20) << val << std::endl; // float: 111111112
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment