我有一个需要根据所选货币转换的价格。
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"currency.plist"];
NSDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
int price = [price intValue];
int currencyValue = [[plistDictionary valueForKey:@"EUR"] intValue];
int convertedCurrency = (price / currencyValue);
price
是一个NSNumber
,valueForKey
也是一个来自 plist 文件的数字,我设置了转换率。
我遇到的问题是我price
缺少小数点。每次我从价格中得到 intValue 时,它都会向上或向下取整。我从 plist 获得的汇率也存在同样的问题。
我已经调查过了NSNumberFormatter
,但它不会让我setFormat
使用 NSNumberFormatter。请问有什么建议吗?