Iphone 使用设备'格式化输出;s的货币设置

Iphone 使用设备'格式化输出;s的货币设置,iphone,cocoa-touch,ios,Iphone,Cocoa Touch,Ios,我正在开发我的第一个iPhone应用程序,希望能够使用设备的货币设置格式化货币 目前我有: - (IBAction)calculate { float lp = ([leftPrice.text floatValue]); float rp = ([rightPrice.text floatValue]); float lw = ([leftWeight.text floatValue]); float rw = ([rightWeight.text float

我正在开发我的第一个iPhone应用程序,希望能够使用设备的货币设置格式化货币

目前我有:

- (IBAction)calculate {

    float lp = ([leftPrice.text floatValue]);
    float rp = ([rightPrice.text floatValue]);
    float lw = ([leftWeight.text floatValue]);
    float rw = ([rightWeight.text floatValue]);

    float lppkg = lp/lw;
    float rppkg = rp/rw;

    if (lp > 0 && lw > 0) {
        leftPricePerKg.text = [[NSString alloc] initWithFormat:@"$%.2f", lppkg];
    }

    if (rp > 0 && rw > 0) {
        rightPricePerKg.text = [[NSString alloc] initWithFormat:@"$%.2f", rppkg];
    }
}

您应该查看NSNumberFormatter-

你可以看看这里:

在这里:

尤其是在

“配置货币格式”部分

编辑

我发现-

//--------------------------------------------
// Format style as currency, output to console
//--------------------------------------------
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
formattedOutput = [formatter stringFromNumber:[attributesDict objectForKey:NSFileSystemFreeSize]];
NSLog(@"Output as currency: %@", formattedOutput);

//--------------------------------------------
// Change local and output as currency
//--------------------------------------------
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"it_IT"];
[formatter setLocale:locale];
formattedOutput = [formatter stringFromNumber:[attributesDict objectForKey:NSFileSystemFreeSize]];
NSLog(@"Output as currency - locale it_IT: %@", formattedOutput);
在这里:

谢谢。我试过以下方法,但都没用。我显然遗漏了一些东西:currency.text=[NSString currencySymbol];