xcode - iPhone: How can I add a currency symbol, decimal point and decimal places in shouldChangeCharactersInRange -


I have found the code given below, which should I am trying to work in UITableView ChangeCharactersInRange event without currency symbol It works fine.

When I try to add the currency symbol, it allows me to enter a number. What should I do, say that I enter 7536, it should be £ 0.07, £ 0.75, £ 7.53, £ 75.36, but instead it is £ 0.07, £ 0.05, £ 0.03, £ 0.06

It looks like

this is the code.

prefix textField: (UITextField *) should change textFieldActressServer: (NSR) category replacement string: (NSString *) string {BOOL RES = TRUE; Double current value = [textField.text double value]; Double cents = round (current value * 100.0f); If ([string length]) {for (size_t i = 0; i <[string length]; i ++) {unicultural c = [string character number index: i]; If (number (c)) {cents * = 10; Cents = c = - '0'; }}} And {// back space st = floor (cents / 10); } // This line works without the next currency symbol //textField.text = [NSString stringWithFormat: @ "% .2f", St / 100.0F]; NSMutableString * aString = [NSMutableString stringWithFormat: @ "% @", strCurrencySymbol]; [Astringepment: @ "% .2f", St. / 100.0F]; TextField.text = aString; Res = NO; Withdrawal reserve;

}

[@ "Pound 1.23" Double Values] 0. If there is a major currency symbol, then you have to leave:

  NSString * currentText = textField.text; NSRange category = [current text limitoffstring: strCurrencySymbol]; If (range.location == 0) {currentText = [current text substringsfind index: range.length]; } Double current values ​​= [current text doublewela]; Generally, I would recommend doing stuff like this: 

  • It will not work with all input methods (and IIRC should not change the cursor in the order of order: it is not) Is called for).
  • Unless you work in the cash register (where they have a "00" key because otherwise "$ 100.00" is a pain) I want to be able to enter "$ 1" and mean $ 1.00 I'm
  • It's not localized.

Comments