How to use NSNumberFormatter for currency to print in UILabel

Discussion in 'iOS Programming' started by int3rc3pt0r, Mar 3, 2010.

  1. int3rc3pt0r macrumors newbie

    Joined:
    Feb 9, 2010
    #1
    Hey Guys ,

    I am a N00b here .

    I print my currency like this :
    Code:
    -(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 ..( A comma sign after every 3 digits , nothing more than that )
    Having a lot of trouble with it ..Please help

    If this can be done without NSNumberFormatter also will help a lot.

    Is my problem same as this link :
    http://groups.jonzu.com/z_apple_using-a-nsnumberformatter-with-a-uitextfield.html


    Thanks in Advance .

    Regards , N00b
     
  2. int3rc3pt0r thread starter macrumors newbie

    Joined:
    Feb 9, 2010
    #2
    I got the answer

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

    Code:
          -(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];	
            }
     

Share This Page