iphone - Custom Number Pad with $ sign -


okay have custom number pad works , shows numbers 0.00 in label (numberfield), need show $0.00.

nsstring *digit = sender.currenttitle; numberfield.text = [numberfield.text stringbyappendingstring:digit];  nsnumberformatter *numberformatter = [[nsnumberformatter alloc] init]; [numberformatter setnumberstyle:nsnumberformatterdecimalstyle]; [numberformatter setgroupingseparator:@""]; [numberformatter setmaximumintegerdigits:4]; [numberformatter setmaximumfractiondigits:2]; [numberformatter setmaximumfractiondigits:2];  numberfield.text = [numberfield.text stringbyreplacingoccurrencesofstring:@"." withstring:@""]; nsdecimalnumber *currency = [[nsdecimalnumber decimalnumberwithstring:numberfield.text] decimalnumberbydividingby: [nsdecimalnumber decimalnumberwithstring:@"100"]]; nsstring *numberfieldformat = [numberformatter stringfromnumber:currency]; numberfield.text = numberfieldformat; 

i tried $%1.2f crashes because not recognize $ sign number. can me out here? or have better way of making custom pad $ sign?

**edit i'm considering making numberfield hidden label (alpha 0) , placing copy (numberfield2) directly on top , running through stringwithformat. works thought there may cleaner way of doing it.

you don't want show $0.00. if i'm in uk? wouldn't want show £0.00?

it looks you're incorrectly using nsnumberformatter. here's how format number currency:

nsnumberformatter *f = [[nsnumberformatter alloc] init]; [f setnumberstyle:nsnumberformattercurrencystyle]; nsstring *string = [f stringfromnumber:[nsnumber numberwithfloat:1234.56]]; [f release]; 

that format things correctly, regardless of locale. it'll use correct currency sign, correct thousands separator, , correct decimal separator. attempting recreate functionality bad idea™.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -