我需要将货币从字符串格式转换为数字格式。
例如我的字符串变量值是@"10 lakh"
. 转换为数字格式的字符串值为 1000000。如何进行这种类型的转换?
(将 100 万转换为 1000000,这就是问题所在)
我需要将货币从字符串格式转换为数字格式。
例如我的字符串变量值是@"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);
}
}
You can make switch cases according to your denominations. By choosing particular switch case you can choose the desired value. I don't think there is predefined method to accomplish this.
hope this helps.