views:

104

answers:

1

Example: I have an NSInteger and I wrap that into an NSNumber object. Now I want to have an NSDecimal with the value of that NSInteger.

So could I ask:

NSDecimal myDecimalFromMyInteger = [myNSNumberObject decimalValue];

Or is this problematic on some way? Or must I always ask for the exact same value as I used to create the NSNumber object?

+6  A: 

This is perfectly fine. From the docs:

"Returns the receiver’s value, expressed as an NSDecimal structure. ... The receiver’s value, expressed as an NSDecimal structure. The value returned isn’t guaranteed to be exact for float and double values."

As long as you're aware of the inherent precision implications, this is a perfectly legal and sane thing to do.

Joshua Nozzi