Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert NSNumber to NSDecimalNumber

I realize that NSDecimalNumber inherits from NSNumber.

However, I am struggling to figure out how I can init an NSDecimalNumber from an NSNumber or how to convert an NSNumber to an NSDecimalNumber.

I have tried

NSDecimalNumber* d = [aNumber copy]; 

where aNumber is an NSNumber object to no avail.

Am I missing something?

Thanks.

like image 780
Michael Rivers Avatar asked Feb 05 '14 05:02

Michael Rivers


1 Answers

You can do:

NSDecimalNumber *decNum = [NSDecimalNumber decimalNumberWithDecimal:[aNumber decimalValue]]; 
like image 198
rmaddy Avatar answered Oct 07 '22 09:10

rmaddy