views:

85

answers:

1

Hi, My app plays a movie and I must keep track of, and interact with the playback time. I use the currentPlaybackTime property to grab a double value of the movie's playback time. I want to use this to trigger some if statements at certain points, But first it would be really helpful if I could convert the value into a value with only 2 decimal places ss.ff where ss are the seconds and ff are the frames. There are 30 frames in a second so it would go 0.29 to 1.0.

Can anyone help me with this? Thanks!

+5  A: 
int seconds = floor(currentPlaybackTime);
int frames = 30 * (currentPlaybackTime - seconds);
double transformedPlaybackTime = seconds + (frames/100.0);

Although I would just work with the individual int seconds and int frames and not make up a fake playback time with the frames as the decimal portion.

aBitObvious
Totally agree with your comment. Trying to use a double to represent something that is not really a floating point number is asking for trouble, *especially* as most of the required values cannot even be represented as doubles. Only frames 0 and 15 can have exact representations, in fact.
JeremyP