Search code examples
iosiphonenumbersdecimal

Will my iOS app calculate figures when a comma is used instead of a decimal point?


New to iOS development and I'm just making a little wage-type calculator for a starter. I'm exploring different features, including making the app available in France and other non-English native countries.

However, as my application is heavily reliant upon calculating figures which have a decimal point in them, I want to know if iOS will calculate the figure if a comma is used as a decimal point, as countries like France use this notation:

Australia/United States/other countries:

12.5 * 15.8 = 197.5

France/other countries:

12,5 * 15,8 = 197,5

I am pretty much asking a) if a comma is inserted rather than a decimal point, will it still calculate on local devices, and b) if not, what code should I include in my application such that it will calculate this notation? (Note that I am not asking for a comma as a separator, but what acts as the equivalent of a decimal point.)

Thank you in advance!


Solution

  • Actually, iOS has a handy class built-in to handle the localization of numerical values. It's called NSNumberFormatter and it specifically has the -setDecimalSeparator: method.