iphone - implemeting a text field input like an atm machines input -


i have text field in iphone app , implement input similar atms input have enter digits (no decimal character input required). want able use numberpad text field. example, text field displays:

0.00 

if user enters sequence 1234 text field this:

12.34 

it have update if user pushes delete button.

for formatting, think you'll happy details in this other post describing how use nsnumberformatter display leading , trailing zeros. pulled , tweaked post:

nsnumberformatter *formatter = [[nsnumberformatter alloc] init]; [formatter setnumberstyle:nsnumberformatterdecimalstyle]; [formatter setformat:@"##0.00"];  nsnumber* input; // hook in input nsstring* output = [nsstring stringwithformat:@"%@", [formatter stringfromnumber:input]]; // hook text field 

in order convert input of 1234 12.34 (and presumably input of 12 0.12), consider shifting decimal of input 2 places.

// int storedinput has been set 1234 int input = 5; // next button pressed storedinput = storedinput * 10 + input; // 1234 * 10 + 5 = 12345 float displayedvalue = input * .01;  // 123.45 nsnumber* output = [nsnumber numberwithfloat:displayedvalue]; 

these 2 code snippets should give idea of how implement these concepts in program. deletion...simply set storedinput 0. call these pieces of code every time there new input keyboard in order refresh value.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -