Search code examples
iosswiftnsnumberformatter

NSNumberFormatter and decimalSeparator issue


I encountered the following problem while using NSNumberFormatter().numberFromString(String) in Swift.
I passed a float value to it separated by "." It worked perfectly on the simulator. But on a device I kept getting optional unwrapping error. I fixed it by using "," as a separator when running on a device. The device and the simulator run the same version of iOS (8.0.3). Can anyone explain what this difference is caused by?

P.S.:- Yes, I can manually set the decimal separator. Just curious why it's different on device/simulator by default?


Solution

  • The decimal separator will be set according to your local language settings.
    Since you seem to have different decimal separators you will probably have different regional settings.