如何限制NSNumberFormatterCurrencyStyle

时间:2013-01-22 00:27:43

标签: nsstring nsnumber nsnumberformatter

我的代码中有这个:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *currency = [defaults objectForKey:@"currencySymbol"];

    NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    text = [text stringByReplacingOccurrencesOfString:@"." withString:@""];
    text = [text stringByReplacingOccurrencesOfString:currencySymbol withString:@""];
    NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
    [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    [numberFormatter setCurrencySymbol:currency];

    NSNumber *number = [NSNumber numberWithDouble:[text intValue]*0.01];
    text = [numberFormatter stringFromNumber:number];
    textField.text = text;

并且它会很有效,直到达到一定数量,然后它不能更高,例如:

  • 2,500.00(可能)
  • 25,000.00(不可能)

也许这是愚蠢的事情,任何人都可以提醒我,我没有看到什么?

感谢。

对于那些遇到同样问题的人,我们必须添加以下代码:

text = [text stringByReplacingOccurrencesOfString:@"," withString:@""];

因为(逻辑上),用于数千......

0 个答案:

没有答案