• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSDecimalNumber & NSString question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: NSDecimalNumber & NSString question
      • From: Ashley Clark <email@hidden>
  • Prev by Date: Passing TableView information into a new dialog
  • Next by Date: Making an invisible Cocoa window catch mouse clicks
  • Previous by thread: Re: Passing TableView information into a new dialog
  • Next by thread: Re: NSDecimalNumber & NSString question
  • Index(es):
    • Date
    • Thread