When I started coding my first application, I used NSNumber for cash, without thinking twice. Then I thought that maybe there were enough types to cope with my values. However, I was advised on the iPhone SDK forum to use NSDecimalNumber due to its excellent rounding capabilities.
Not being a temperament mathematician, I thought the mantissa / exponent paradigm might be redundant; still, googlin 'around, I realized that most of the money / currency talk in cocoa was passed on to NSDecimalNumber.
Please note that the application I'm working on will be internationalized, so the ability to calculate the amount in cents is not really viable, because the monetary structure is highly dependent on the language used.
I am 90% sure that I need to go with NSDecimalNumber, but since I did not find a definite answer on the Internet (something like: "if you are dealing with money, use NSDecimalNumber!") I thought I would ask here. Perhaps the answer is obvious to most, but I want to be sure before starting a massive redistribution of my application.
Convince me :)
cocoa-touch rounding cocoa currency
nutsmuggler Jan 07 '09 at 18:29 2009-01-07 18:29
source share