Re: A Newbie Float Problem
Re: A Newbie Float Problem
- Subject: Re: A Newbie Float Problem
- From: Bergmann Manfred <email@hidden>
- Date: Fri, 16 Dec 2005 14:17:50 +1100
Hi Jonathan.
For float values you should use the "%f" format sequence. "%d" is for
integer values and that's why you see the odd number.
Have a look here: file://localhost/Developer/ADC Reference%
20Library/documentation/Cocoa/Conceptual/DataFormatting/Articles/
FormatStrings.html
(I hope the file URL works for you otherwise search for
"FormatStrings" on the Apple Homepage)
best regards,
Manfred
Am 16.12.2005 um 14:09 schrieb Jonathan Faulkenberry:
Hi all,
I am relatively new to Cocoa, although I have some experience with
some basic C. For some reason though, I am having trouble creating
a small app I am using to help me learn Cocoa. This app is supposed
to hold a float value named "money" an have two buttons, one which
will call addMoney: (which will add 5 to the float value) and one
called drink: (which will decrease the float value by 5). For some
reason, when I click on the button that calls addMoney:, the value
of the float goes to like a 10 digit number. I am almost positive I
have everything right in my header file and nib, so I'm guessing it
is something in my .m file. Here is the code: (I haven't finished
all of the methods yet since the float won't work right). Any help
would greatly appreciated. Thanks in advance.
#import "AppController.h"
@implementation AppController
- (id) init {
self = [super init];
if (self != nil) {
money = 0.00;
NSLog(@"init");
NSLog(@"Money = %d", money);
}
return self;
}
- (void) awakeFromNib
{
[textField setStringValue:[NSString stringWithFormat:@"%d", money]];
}
- (IBAction)addMoney:(id)sender
{
money = money + 5;
NSLog(@"Money = %d", money);
}
- (IBAction)drink:(id)sender
{
}
- (float)money
{
return money;
}
- (void) dealloc
{
[super dealloc];
}
@end
Jonathan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40software-by-mabe.com
This email sent to email@hidden
--
software by MABE
http://www.software-by-mabe.com
_______________________________________________
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