0

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 by Nick Evan: Added CODE-tags

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by Feim
0

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.

0

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.precision(10);
		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 by Nick Evan: Added CODE-tags

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.