轉換貨幣格式到數字格式
比如字符串變量是@"10 lakh"
轉換成數字值後應該是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);
}
}