swift - Currency formatting not working -
i have updated gm of xcode 6 , going through , fixing issues.
i have issue particular part of code have been struggling fix. used have code:
override func viewdidload() { currencyformatter.numberstyle = nsnumberformatterstyle.currencystyle currencyformatter.currencycode = nslocale.currentlocale().displaynameforkey(nslocalecurrencysymbol, value: nslocalecurrencycode)! } func textfielddidchangevalue(textfield: uitextfield) { //automatic formatting transaction value text field. target added above. var text = textfield.text.stringbyreplacingoccurrencesofstring(currencyformatter.currencysymbol, withstring: "").stringbyreplacingoccurrencesofstring(currencyformatter.groupingseparator, withstring: "").stringbyreplacingoccurrencesofstring(currencyformatter.decimalseparator, withstring: "").stringbyreplacingoccurrencesofstring(" ", withstring: "") // there special character here. line critical european/other currencies. println(textfield.text) textfield.text = currencyformatter.stringfromnumber((text nsstring).doublevalue / 100.0) currencydouble = (text nsstring).doublevalue / 100.0 //println(currencydouble) valueenter.alpha = 100 }
i had change code in viewdidload() app crashing, this:
let currencyformatter = nsnumberformatter() currencyformatter.numberstyle = nsnumberformatterstyle.currencystyle if let currencycode = nslocale.currentlocale().objectforkey(nslocalecurrencysymbol) as? string { currencyformatter.currencycode = currencycode println(currencyformatter.currencycode) //will display "$", example, if locale set usd }
the app no longer crashes formatting doesn't work. i've tried few things haven't been able figure out how fix it.
you're setting currencycode
using nslocalecurrencysymbol
value. is, name suggest, wrong value. correct value nslocalecurrencycode
.
Comments
Post a Comment