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??
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?
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