Re: Formatting integer value
Re: Formatting integer value
- Subject: Re: Formatting integer value
- From: Andy Armstrong <email@hidden>
- Date: Mon, 14 Feb 2005 13:21:31 +0000
On 14 Feb 2005, at 13:18, Charlton Wilbur wrote:
On Feb 14, 2005, at 8:02 AM, René Korthaus wrote:
i have a problem: I read an integer value from an xml file (plist
format) which is the duration of a song.
The formatted integer value is like "325407", where 325 are seconds
and 407 are milliseconds. Now i want to make a 3:25 string out of it
to display the duration of that song in a tableview. I cannot figure
out how to drop the 407ms off that integer value.
You could treat it like a string and chop off the rightmost three
characters. See the -stringValue method of NSNumber, and the
+stringWithFormat:, -substringFromIndex:, -substringToIndex:, and
-substringWithRange: messages in NSString.
You could treat it like an integer, and do an integer division by 1000.
It's probably also worth noting that 325 seconds is *not* the same as
3 minutes and 25 seconds. In that case you'll have to do some (fairly
basic) math to convert.
int time = 325407;
int ms = time % 1000;
int s = time / 1000 % 60;
int min = time / 60000;
--
Andy Armstrong, hexten.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden