Hi all,

I have this string "May 19, 2009 15:39:41.606809000" , i need to get the seconds into a double variable.
My code is like this:

double sec;
string seconds = str.substr(19,10);
istringstream(seconds) >> sec;

The thing is that seconds = 41.6068090 , but sec = 41.6068

Why doesn't the number of digits is lower?

Any guess?
Thanx in advance

Edited 6 Years Ago by Nick Evan: Added CODE-tags

it may be the display of the value, not the actual value itself that's the problem. Try adjusting the display with ostream modifiers like setprecision, setwidth, etc.

Thanks, now it displays correctly!
But, i save this values in a file:

double sec;
               double secundo;

                seconds = str.substr(19,10);
		istringstream(seconds) >> sec;
		cout.setf(ios::fixed, ios::floatfield);
		cout << "sec: " << sec << endl;
		secundo = ((min*60)+sec);
		cout << secundo<< endl;
		frames[i].timesec = secundo;

myfile.open ("Exemplo.csv", ios::out | ios::app);
	myfile << "Frame.time_delta" << ";" << "Frame.timesec" << ";" << "Frame.lenght" << ";" << endl;
	for(i=1; i<= k ; i++)
		myfile << frames[i].time_delta << ";" << frames[i].timesec << ";" << frames[i].lenght << endl;

Secundo is also displaying right, but when i save into a file the value is displayed without the .precision(10), how do i instruct to save with the same precision?

Edited 6 Years Ago by Nick Evan: Added CODE-tags

This question has already been answered. Start a new discussion instead.