 |
 |
Beginner Cocoa Help
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2006
Location: Canada
Status:
Offline
|
|
Well after following Apple's Currency Converter tutorial for Cocoa, I decided to make my own app. I use the same basic layout, except modified. Basically my program converts measures and beats into minutes and seconds. It works so far except I have one problem, when it displays seconds if it is less than 10 it just says the number like 7 instead of 07 so I was wondering how would I make it always have 2 digits? Here is the source so far:
float measures, beats, MtoB, BPM, BPS, totalBeats, seconds, minutes;
measures = [MeasuresField floatValue];
beats = [BeatsField floatValue];
BPM = [BPMField floatValue];
measures = measures - 1; /*garageband uses a base of 1, so technically when it has a 2 in the measures column, it is actually only 1 full measure*/
MtoB = measures * 4; /*converts the measures to beats*/
beats = beats - 1; /*garageband also uses a base of 1 in the beats column*/
totalBeats = MtoB + beats;
BPS = BPM / 60;
seconds = totalBeats / BPS;
minutes = seconds / 60;
minutes = (int)minutes;
seconds = seconds - (minutes * 60);
[SecondsField setFloatValue:seconds];
[MinutesField setFloatValue:minutes];
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Aug 2001
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status:
Offline
|
|
I think a format of @"%02d" will do the trick.
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
You could also just hook the field up to an NSNumberFormatter in the nib.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Jul 2006
Location: Canada
Status:
Offline
|
|
Originally Posted by Chuckit
You could also just hook the field up to an NSNumberFormatter in the nib.
Thanks for the help, but I found this method the best. All i had to do was drag the NSNumberFormatter onto the NSTextField and then change the settings in the Formatter panel. It worked great and was really easy for a beginner like me.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |