Possible Duplicate:
Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273?
Here is my code
#include <sstream>
#include <iomanip>
#include <string>
#include <iostream>
int main(int ac, char **av)
{
if (ac > 1)
{
std::string input = av[1];
std::stringstream ss;
double output;
ss << input;
ss >> output;
std::cout << std::fixed << std::setprecision(2) << output << std::endl;
}
}
I'm trying to convert a string to a double using stringstreams.
It works, but it acts very weirdly when using very big numbers:
./a.out 999999999999999999999999
999999999999999983222784.00
./a.out 42
42.00
How can i handle all double values?