objective c - Find locale currency for iphone programmatically -
i want find out currency locale on user's iphone programmatically. means, if user in store, currency locale should usd, australia, should aud. purpose of task try convert item price listed on our app match price appstore ask.
for example, if sell video 3 usd, , australian wants buy it, should show 2.8 aud in app screen. reduce calculation in user on real price in country. know how it?
in cases currency symbol won't enough. example, in germany write our prices this: 1,99€ people in use $1.99. there 3 differences in string. currency symbol, position of , separator.
if want right should use nsnumberformatter. takes care of differences between currency formats. , better you. because currencies, not 4 main currencies want support.
nsnumberformatter *formatter = [[nsnumberformatter alloc] init]; [formatter setnumberstyle:nsnumberformattercurrencystyle]; [formatter setlocale:[nslocale currentlocale]]; nsstring *localizedmoneystring = [formatter stringfromnumber:mycurrencynsnumberobject];
if want use in app purchase can't rely on users current locale, because possible use us-based account on device de (german) locale. , price of item (actual price 0,79€ in germany) show 0,99€ (because costs $0.99 in us). wrong. localized price app store, there no need calculations on own.
, price , pricelocale each of skproducts.
you correct formatted currency string this:
skproduct *product = [self.products objectatindex:indexpath.row]; nsnumberformatter *formatter = [[[nsnumberformatter alloc] init] autorelease]; [formatter setnumberstyle:nsnumberformattercurrencystyle]; [formatter setlocale:product.pricelocale]; currencystring = [formatter stringfromnumber:product.price];
edit: since asked currency code.
you can nsstring *currencycode = [formatter currencycode];
give currency code according iso 4217. aud, usd, eur , on.
Comments
Post a Comment