• 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
Re: Newbie questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie questions


  • Subject: Re: Newbie questions
  • From: Prachi Gauriar <email@hidden>
  • Date: Tue, 7 Jun 2005 10:28:55 -0400

On Jun 7, 2005, at 4:03 AM, Joe Osborn wrote:
On Jun 7, 2005, at 3:32 AM, Andy Bettis wrote:
Another common requirement in my apps is a field to hold money values. I would store this as a long holding the number of pennies and use utility classes to format, read and validate it. In all the money examples I've seen for Cocoa people just use a float and use NSFormatter classes for UI formatting. I must admit to some trepidation as I look at floats in the debugger and see 12.00 shown as 11.9999998, especially as some of my supported apps have big lists of numbers to be totalled and rounding errors are not permitted by accountants! Am I worrying needlessly? Anyone have experience with this?

I would say to use the NSDecimalNumber class. It's a decimal- format floating point number, so you won't get rounding errors. When you display, get the decimal number's double value approximation and put it into a (whatever UI element) with a number formatter and all will be well.

NSDecimalNumber is on its way to being deprecated[1], so you probably shouldn't go that route. I see nothing wrong with using a long as you mentioned.


-Prachi

[1] Foundation Release Notes for Tiger -
    <http://developer.apple.com/releasenotes/Cocoa/Foundation.html>
_______________________________________________
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


References: 
 >Newbie questions (From: Andy Bettis <email@hidden>)
 >Re: Newbie questions (From: Joe Osborn <email@hidden>)

  • Prev by Date: Re: NSOutlineview, data changing from outside the outlineview's events
  • Next by Date: Re: Where to find _objc_insertMethods
  • Previous by thread: Re: Newbie questions
  • Next by thread: Newbie UI questions
  • Index(es):
    • Date
    • Thread