I’m converting an algorithm I wrote in Java to Objective-C. In java the BigDecimal class handles base-10 numbers and can take the primitive double as a constructor arg. In Cocoa’s NSDecimalNumber class, however, there is no direct way to construct an instance using a primitive double.
Currently I’m using this (smelly) hack:
[NSDecimalNumber decimalNumberWithString:[NSString stringWithFormat:@'%1.38f', number]];
Is there a better way?
NSNumber, the superclass of NSDecimalNumber, has a +numberWithDouble: method. That’s what you want.