0

I've got a small chunk of code which I've noticed is behaving differently for arm64 targets. I'm fetching a numeric string from JSON data, and then using integerValue to convert the string to an integer. The string generally has thousands separators, in the form of a comma.

On non-64bit targets, (iPhone 4/s, 5/s, etc), everything works perfectly and I get the correct integer regardless of whether there is a comma separating the thousands. However, on arm64, integerValue only returns the first "chunk" of numbers, before the separator comma. I've included the code and a sample result to show what exactly is happening:

NSInteger value = [BTCValue integerValue];
[UIApplication sharedApplication].applicationIconBadgeNumber = value;

For example, on non-64bit targets: BTCValue = @"54,321.00" and value = 54321.

On arm64 targets, however: BTCValue = @"54,321.00" and value = 54.

It doesn't seem to matter whether value is an int or an NSInteger, the same thing happens regardless. Is there something that I'm missing? I don't understand why everything works properly on armv7 but not arm64.

Radrider33
  • 557
  • 1
  • 4
  • 17
  • 1
    The idea that the processor is the factor causing this is a little hard to swallow. Are you sure the localization on your arm64 device is the same as the others? – jscs Jan 05 '14 at 20:52
  • I'm running the same code on the iPhone simulator. Locale on both is the same. – Radrider33 Jan 05 '14 at 20:57
  • Can you clarify that remark? _None_ of your testing is on a device? Or you've tested on: a) non-64-bit devices, b) 64-bit devices, c) non-64-bit simulator, **and** d) 64-bit simulator? And _both_ b and d display this behavior, while a and c do not? – jscs Jan 05 '14 at 21:01
  • I've tested on both the simulator and non-64bit devices, but not on a 64bit **device**, which I don't currently have access to. I've only been able to get this behavior on the 64bit _simulator_, but I don't know if it would occur on an actual device or not. – Radrider33 Jan 05 '14 at 21:08

1 Answers1

4

It's likely that your ARM64 device has a locale setting that is causing the comma to be treated as a decimal or simply as non-numeric text.

In general, you're better off using NSNumberFormatter.

Apple docs on NSNumberFormatter

Jeff Wolski
  • 6,332
  • 6
  • 37
  • 69
  • I'll give it a shot with NSNumberFormatter. The strange thing is that this is occurring on the iPhone simulator; I know that all of my simulators are set to the same locale. – Radrider33 Jan 05 '14 at 21:00
  • 1
    You _know_, or you've _checked_, @Radrider33? It's possible to have different number formatting settings on the different simulators. – jscs Jan 05 '14 at 21:07
  • And you're certain that each of your scenarios has a comma in the string? – Jeff Wolski Jan 05 '14 at 21:07