我想把数字13456显示为13.456K,3456789显示为34.56L,请问IOS有格式化工具可以转换成K(thousand),L(Lakh),M(Million),C(Crore)后缀吗?
最佳答案
iOS
中没有库或 sdk 可以使用 K(千)、M(百万) 等缩写来缩短或转换货币 em>L(十万),C(千万)等,因为这些缩写在不同的国家和地区是不同的。
您必须根据您的号码所属的类别转换号码,并使用 NSNumberFormatter
和 NSNumberFormatterCurrencyStyle
您可以根据您的要求格式化您的号码。
您可以根据需要使用以下代码转换货币金额:
float shortenedAmount = actualAmount;
NSString *suffix = @"";
if(currency >= 10000000.0f) {
suffix = @"C";
shortenedAmount /= 10000000.0f;
}
else if(currency >= 1000000.0f) {
suffix = @"M";
shortenedAmount /= 1000000.0f;
}
else if(currency >= 100000.0f) {
suffix = @"L";
shortenedAmount /= 100000.0f;
}
else if(currency >= 1000.0f) {
suffix = @"K";
shortenedAmount /= 1000.0f;
}
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithFloat:shortenedAmount]];
NSString *requiredString = [NSString stringWithFormat:@"%@%@", numberAsString, suffix];
关于ios - 格式化带有印度后缀的货币 IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30436412/