Is NSNumberFormatter the only way to format an NSDecimalNumber?

Posted by Paul Alexander on Stack Overflow See other posts from Stack Overflow or by Paul Alexander
Published on 2010-05-30T21:39:26Z Indexed on 2010/05/30 21:42 UTC
Read the original article Hit count: 652

Filed under:
|
|

I'm using an NSDecimalNumber to store money in Core Data. I naively used stringWithFormat: at first to format the value, later realizing that it didn't support NSDecimalNumber and was instead formatting the pointer :(. So after some reading through the docs I learned to use the NSNumberFormatter to get the format I wanted. But this just strikes me as the "hard way". Is there any easier way than this:?

NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle: NSNumberFormatterCurrencyStyle];
priceField.text = [formatter stringFromNumber: ent.price];
[formatter release];

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c