string to double

Hello!
i have a problem converting from string to double.
I read a string containing my value from a file.
getline (myfile,riga_3);
risultato = atof(riga_3.c_str());

If i print out the string, i can see that the string is 0.056999999999999995.
Now, if i print out the value of risultato, that is a double, it's 0.057.

How can i copy into my double variable "risultato" the whole string, with the same precision??

Thanks
That depends upon which function you are using to print out the value of risultato. If you are using printf(), there are flags that will help you control the precision. If you are using streams, look into the iomanip class.
i tried with both cout and printf:
the string is: 0.056999999999999995
the printed value with "cout << risultato" is: 0.057
the printed value with "printf("\t\tprintf %1.6f\n",risultato);" is: 0.057000

so i don't think the problem is to print out the real value, but the value copied into risultato.
Is it wrong?
You didn't apply any manipulation to the line with cout above. Try this:

1
2
3

cout << "risultato is: " << setprecision( 18 ) << risultato << endl;
Yes, ok, but my problem is that, as you can see from the printf command, the value stored in risultato is not the same one of the string, I tried also with "setprecision" but is the same
Have you tried strtod(riga_3.c_str()) ?
yep... it's the same with atof or strtod :(
I've never seen this happen before. I can't test now, but when i get to my lab I'll give you an answer.
Topic archived. No new replies allowed.