views:

355

answers:

1
NSNumberFormatter * fmt;
NSNumber          * n;

fmt = [ [ NSNumberFormatter alloc ] init ];
n   = [ NSNumber numberWithFloat: 10 ];

[ fmt setFormatterBehavior: NSNumberFormatterBehavior10_4 ];
[ fmt setCurrencySymbol: @"$" ];
[ fmt setNumberStyle: NSNumberFormatterCurrencyStyle ];

 // NSLog( @"%@", [ fmt stringFromNumber: n ];

[ fmt release ]


-(IBAction)buttonPressed1:(id)sender
 {
double currency = [Amount1.text doubleValue] + [Amount2.text doubleValue]; 

SumCurrency.text = [NSString stringWithFormat:@"%0.0f", currency];


 }

How do I get the SumCurrency.text formated as 1,999 instead of 1999

Please help .. I am new to Objective - C , but my project is almost 95 % on interface builder .

I just need help with above code to implement .. Please I am struggling a lot with this .

Regards , Newbie.

A: 

I got the answer .. But for anyone's future refernce

    -(IBAction)buttonPressed1:(id)sender
     {
    double currency = [Amount1.text doubleValue] + [Amount2.text doubleValue]; 
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithInt:currency]];
SumCurrency.text = [NSString stringWithFormat:@"Converted:%@",numberAsString];  
    }