Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

hellrider

macrumors regular
Original poster
Jun 7, 2008
101
0
Pennsylvania
I have an NSTimer that spits out a float value every 1/16th of a second. (Every 1/16th of a second, 1/16 of a second is taken off the float value).

The application functions as a countdown timer, so I want the raw fractional seconds (i.e. 9.9375) to be converted into (hours:minutes:seconds:000).

This is somewhat hard to explain, and I apologize, but right now, I have an NSString that looks like 9.xxxx; my goal is for it to look like 00:00:9:xx:xx.

If this is possible, I would appreciate some guidance.

Thanks.
________
 
The usual way to do this is by a combination of truncation, subtraction, and multiplication.

9.9375 truncated gives 9
9.9375 - 9 gives 0.9375
0.9375 times 100 gives 93.75
93.75 truncated gives 93
and so on.

Put together your string with these intermediate results.

You use a similar process to get hours:minutes:seconds. Divide by secondsPerHour to get hours. Etc.

BTW, timers aren't guaranteed to fire exactly on the times that they've been told to fire. It's considered better to subtract the current time from the start time to get the elapsed time rather than simply increment/decrement the time.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.