Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Question #1</strong>: Should my thirtyYear property be NSDecimal or NSDecimalNumber?</p> <p>As you stated if you're dealing with any financial calculations always use NSDecimalNumber and NSDecimalNumber provides predictable rounding behavior and precision when performing base 10 calculations.</p> <p>If you want more detailed information this is from the Apple Documentation directly:</p> <blockquote> <p>NSDecimalNumber is an immutable subclass of NSNumber that provides an object-oriented wrapper for doing base-10 arithmetic. An instance can represent any number that can be expressed as mantissa x 10 exponent where mantissa is a decimal integer up to 38 digits long, and exponent is an integer between -128 and 127.</p> </blockquote> <p>Now in regards to NSDecimal, this is a C struct and not as easy to work with in Objective C. As stated above that's where the NSDecimalNumber object comes in which is made to work with object oriented languages. In short NSDecimalNumber is the way to go. It is easier to work with.</p> <p><strong>Question #2</strong>: When dividing within the getThirtyYear() method should I use NSDecimalNumber for the arithmetic?</p> <p>If precision calculations are crucial in your app then yes use NSDecimalNumber since they're guaranteed to be accurate.</p> <p>Since you will be using NSDecimalNumber I suggest checking out the <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDecimalNumber_Class/Reference/Reference.html" rel="nofollow">NSDecimalNumber Class Reference</a> because the class has a number (no pun intended) of useful methods. Hope this helps.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload