formatting currency output in ios -


- (void)textfielddidendediting:(uitextfield *)textfield  {     if (textfield1) {          nsstring *txt = self.textfield1.text;          double num1 = [txt doublevalue];          double tcost = num1 /100;          nsnumberformatter *numberformatter = [[nsnumberformatter alloc] init];          [numberformatter setnumberstyle: nsnumberformattercurrencystyle];           nsstring *numberasstring = [numberformatter stringfromnumber:[nsnumber numberwithfloat:tcost]];          self.textfield1.text = [nsstring stringwithformat:@"%0.@",numberasstring];     } } 

this code ive put formats output of textfield currency im trying work out how format currency output is,

if types in 1625 formats 0.1625 if somone types in 50 formats 0.50 correct supposed calculator taking in peoples electricity rates either in cents or pences.

to currency formatting use following code :

- (nsstring*) getamountincurrencyformatwithvalue:(nsstring*) valuestring {      nsnumberformatter *numberformatter = [[nsnumberformatter alloc] init];     [numberformatter setnumberstyle: nsnumberformattercurrencystyle];     nsstring *numberasstring = [numberformatter stringfromnumber:[nsnumber numberwithdouble:[valuestring doublevalue]]];      return numberasstring; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -