在我的 CoreData Base 中是一个值 12500.00,它存储为 12500。
我想把它放在一个 tableview 标签中,我想有一个像货币一样的 2 位数字。
var unit = "€"
textLabel.text = ("%@ %.2f" ,unit, (entityName[indexPath.row].price!))`
我在我的标签中只得到带有小数点的数字,如 12500,55 欧元,而不是 12500,00 欧元
在我的 CoreData Base 中是一个值 12500.00,它存储为 12500。
我想把它放在一个 tableview 标签中,我想有一个像货币一样的 2 位数字。
var unit = "€"
textLabel.text = ("%@ %.2f" ,unit, (entityName[indexPath.row].price!))`
我在我的标签中只得到带有小数点的数字,如 12500,55 欧元,而不是 12500,00 欧元
let currency = "€"
let costAsString = String(format: "\(currency) %.2f", Double(12500))
print(costAsString) // € 12500.00
我会使用NSNumberFormatter
:
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle;
NSString *currencyString = [numberFormatter stringFromNumber: price];
(对不起,代码在ObjectiveC
)