I am a N00b here .
I print my currency like this :
-(IBAction)buttonPressed1:(id)sender
{
double currency = [Amount1.text doubleValue] + [Amount2.text doubleValue];
SumCurrency.text = [NSString stringWithFormat:@"%0.0f", answer];
}
I just simply want to use NSSNumberFormatter to print the SumCurrency.text in US Currency format .. Having a lot of trouble with it ..Please hekp
same issue ??? http://groups.jonzu.com/z_apple_using-a-nsnumberformatter-with-a-uitextfield.html
Thanks in Advance .
Regards , N00b
Using float or double (floating point arithmetic) with money is a very bad idea because precision errors. You should use fixed-point arithmetic, aka NSDecimalNumber.
This is an example of a situation where categories in Objective-C shine.
The cleanest solution is to create a category for NSNumber. .h:
and .m:
In your code, you'd have to #import "NSNumber+Formatter.h" and simply do this:
Very clear and clean.
I got the answer .. But for anyone's future reference
or, in Swift: