NSDecimalNumber & NSString question
NSDecimalNumber & NSString question
- Subject: NSDecimalNumber & NSString question
- From: "Brooke Gravitt" <email@hidden>
- Date: Tue, 18 Nov 2008 17:28:55 -0500
Hello,
I'm trying to better acquainted with Cocoa and Obj-C, having some
trouble with simple things. Perhaps someone could kindly apply cluebat
to skull for me.
I'm accepting a couple of string values from a pair of NSTextField and
would like to take these values and do some math with them, then
display them back in a Label.
....
NSString *aString = aField.text;
NSString *bString = bField.text;
NSDecimalNumber *aAmt = [NSDecimalNumber decimalNumberWithString:aString];
NSDecimalNumber *bAmt = [NSDecimalNumber decimalNumberWithString:bString];
NSDecimalNumber *myTotal;
NSDecimalNumber *myPct;
NSDecimalNumber *multFactor;
myPct = [bAmt decimalNumberByDividingBy:100]; // divide by 100 to get
% ( 0.XX )
multFactor = [myPct decimalNumberByAdding:1]; // add 1 so we can
multiply by 1.XX
newAmt = [bAmt decimalNumberByMultiplyingBy:myPct];
myTotal = [aAmt decimalNumberByAdding:bAmt];
aLabel.text = newAmt;
bLabel.text = myTotal;
[aString release];
....
None of this works, at all. So how to I grab 2 strings from text
fields, extract their numerical value, do some math, then apply them
to labels?
Regards,
Brooke
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden