Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 08-25-2009, 11:00 AM   #3 (permalink)
deansx
Objective-C Code Monkey
 
deansx's Avatar
 
Join Date: May 2009
Location: Mountain View, CA
Posts: 127
deansx is on a distinguished road
Default

Quote:
Originally Posted by Eagle11 View Post
I have a question about formatting a string. I have a timer in my app that displays hour:min:sec. Right now I am using this line:

Code:
NSString *nssTimer = [NSString stringWithFormat:@"%2i:%2i:%2i", nsiTimerHour, nsiTimerMin, nsiTimerSeconds];
to format the string. The problem is that is ends of looking like this
#: #: #
when the numbers are less than ten. I want it to look like this
##:##:##
regardless of what the values are.
Is there a way to achieve that?
I have some code that displays minutes:seconds:tenths. I want the minutes and seconds to be two digits, even if there are less than 10 of either. The formatting that works for me is:
Code:
[self setText:[NSString stringWithFormat:@"%02d:%02d.%1d",dispMins,dispSecs,tsecs]];
Will give output, of:

Quote:
02:08.3
for 2 minutes, 8 and 3 tenths seconds.

Good luck!
deansx is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,172
Threads: 93,917
Posts: 402,134
Top Poster: BrianSlick (7,966)
Welcome to our newest member, myrtaah95
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 11:44 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.