gpt4 book ai didi

iphone - iOS 中不同语言环境的货币格式化程序

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

我想将此字符串:1000000 转换为以下格式:10,00,000 但是,我得到的输出是这样的:1,000,000是错的。我需要 10,00,000

我的代码:

NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
inputnumber = newString;
NSNumberFormatter* formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setCurrencySymbol:@""];
[formatter setMaximumFractionDigits:2];
[formatter setMinimumFractionDigits:2];
[formatter setUsesGroupingSeparator:YES];
[formatter setCurrencyGroupingSeparator:@","];
// [formatter setCurrencyDecimalSeparator:@"."];
[formatter setGroupingSeparator:@","];
NSNumber *num = [NSNumber numberWithDouble:[inputnumber doubleValue]];
inputnumber = [formatter stringFromNumber:num];

最佳答案

这是一种印度货币格式。因此,您必须将 @"en_IN" 设置为 currencyFormatter Locale

工作代码:

NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setCurrencySymbol:@""];
[currencyFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_IN"] autorelease]];
NSLog(@"Final Value :: %@", [currencyFormatter stringFromNumber:[NSNumber numberWithFloat:1000000]]);

关于iphone - iOS 中不同语言环境的货币格式化程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17463298/

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