iphone - 如何将货币从字符串格式转换为数字格式?

标签 iphone ios objective-c

我需要将货币从字符串格式转换为数字格式。

例如,我的字符串变量值为@"10 lakh"。转换为数字格式的字符串值为1000000。如何进行这种转换?

(将100万转换为1000000,这就是问题所在)

最佳答案

尝试

- (NSNumber *)multiplierForKey:(NSString *)key
{

    NSDictionary *dict = @{@"thousand":@1000, @"lakh":@100000, @"million":@1000000, @"crore":@100000000};
    NSNumber *value = dict[[key lowercaseString]];
    return value?value:@1;
}

- (void)findMultiplier{

    NSString *string = @"10 lakh";

    NSArray *components = [string componentsSeparatedByString:@" "];

    if ([components count]==2) {
        NSNumber *value = components[0];
        NSString *key = components[1];
        NSNumber *multiplier = [self multiplierForKey:key];

        NSDecimalNumber *decimalValue = [NSDecimalNumber decimalNumberWithDecimal:[value decimalValue]];
        NSDecimalNumber *multiplierValue = [NSDecimalNumber decimalNumberWithDecimal:[multiplier decimalValue]];

        NSDecimalNumber *finalValue = [decimalValue decimalNumberByMultiplyingBy:multiplierValue];
        NSLog(@"Value : %@",finalValue);
    }
}

关于iphone - 如何将货币从字符串格式转换为数字格式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16914458/

相关文章:

ios - NSString 在 CoreData 谓词中作为 float

ios - 如何在 IOS 中重新加载 UIBarButtonItem

ios - OCMock 抛出 EXC_BAD_ACCESS

ios - 如果我选择一行或移动一个 uitableview,将调用 "moveRowAtIndexPath"

objective-c - iOS - GANTracker 没有什么可调度的

iphone、ipad VGA 外部显示器 - tvOutManager

ios - 无法将新项目保存到表格 View

iphone - UIScrollView动态调整UILabel的大小

ios - 如何设置最大音量? ios, 音频单元

iphone - UI键盘类型