ios - 格式化带有印度后缀的货币 IOS

标签 ios

我想把数字13456显示为13.456K,3456789显示为34.56L,请问IOS有格式化工具可以转换成K(thousand),L(Lakh),M(Million),C(Crore)后缀吗?

最佳答案

iOS 中没有库或 sdk 可以使用 K(千)M(百万) 等缩写来缩短或转换货币 em>L(十万)C(千万)等,因为这些缩写在不同的国家和地区是不同的。

您必须根据您的号码所属的类别转换号码,并使用 NSNumberFormatterNSNumberFormatterCurrencyStyle 您可以根据您的要求格式化您的号码。

您可以根据需要使用以下代码转换货币金额:

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/

相关文章:

ios - 使用 iOS 5 启动时应用程序崩溃 - 无法重现

ios - 闪存 AS3 AIR 3.0 iOS : Timer optimization?

ios - steroids.js 如何在默认情况下和加载页面上禁用导航栏

ios - 在滑动手势、iOS、Swift 上将 View 更改为圆圈

ios - 核心数据是一种图数据库吗?

iphone - 如果标签有重音,NSXMLParser 不会获取所有标签

ios - UIScrollViews subview 没有在纵向到横向方向更改上调整自己的大小

android - ibeacon(信标)能否模仿NFC近距离发送通知?

ios - 在 swift、iOS 10 中覆盖音量来拍照

ios - 点击segmentedControl会出现无法识别的选择器错误