Quote:
Originally Posted by themaccity
Hi,
I'm using a UITextField and the Keyboard format is "Number Pad," which does not include a button for a "." Is it possible for the UITextField to auto-add a decimal into the user's entry.
For instance, when the user taps in the numbers "3012" the TextField changes the number to "30.12", or when the user taps "40331" the TextField changes the number to "403.31"? In a sense i'm wanting the TextField to add a decimal 2 spaces after the final number.
|
The easiest way to do that would be to take the users input as text, parse it, and write the text back to the field in the form you want it.
You might be able to use a number formatter (NSNumberFormatter) to get the effect you want, but I'm not sure, and it would be pretty easy to say "if there's no decimal in the string, add one 2 characters from the end. Else leave it alone because there's already a decimal. It would be 2 or 3 lines of code, tops.