gpt4 book ai didi

ios - NSNumberFormatter 在负值上显示括号

转载 作者:可可西里 更新时间:2023-11-01 05:55:24 25 4
gpt4 key购买 nike

<分区>

我希望格式化程序将 -£4.00 显示为 -£4.00 但它一直显示为 (£4.00),这是为什么?

下面的这个函数将字符串“00000014”变成“£00.14”,它也应该变成负值。但是数字格式化程序似乎添加了括号。

代码如下:

+(NSString *)pfsCurrencyAmountString:(NSString *)amount CurrencyCodeAsString:(NSString   *)code{

if (amount == nil) {
return nil;
}

int amountLength = [amount length];
NSMutableString *amountMutable = [NSMutableString stringWithString:amount];

if (amountLength > 2) {
[amountMutable insertString:@"." atIndex:amountLength - 2];
}

NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];

NSNumberFormatter *currencyStyle = [[NSNumberFormatter alloc] init];
[currencyStyle setFormatterBehavior:NSNumberFormatterBehavior10_4];
[currencyStyle setNumberStyle:@"NSNumberFormatterCurrencyStyle"];
[currencyStyle setLocale:locale];
[currencyStyle setCurrencyCode:code];

NSNumber * balance = [currencyStyle numberFromString:amountMutable];
[currencyStyle setNumberStyle:NSNumberFormatterCurrencyStyle];

return [currencyStyle stringFromNumber:balance];
}

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