gpt4 book ai didi

iphone - 有没有办法在 iOS 中为 float 添加逗号,或者至少将其显示为货币?

转载 作者:行者123 更新时间:2023-11-28 20:27:38 25 4
gpt4 key购买 nike

我有以下内容:

NSLog(@"Total: $%.2f", paymentsToday);

目前显示:

$16000.00

如何让它显示:

$16,000.00

最佳答案

你应该使用 NSNumberFormatter为此。

这应该可以解决问题:

NSNumberFormatter *priceFormatter = [[NSNumberFormatter alloc] init];
[priceFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[priceFormatter setCurrencyCode:@"USD"];
[priceFormatter setCurrencySymbol:@"$"];
NSString *formattedOutput = [priceFormatter stringFromNumber:[NSNumber numberWithFloat: paymentsToday]];
NSLog(@"Total: %@", formattedOutput);

关于iphone - 有没有办法在 iOS 中为 float 添加逗号,或者至少将其显示为货币?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13436308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com