0

我的代码中有这个:

    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:@""];

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

4

0 回答 0