NSDecimalNumber and large unsigned long long (64-bit) integers

后端 未结 2 596
野趣味
野趣味 2021-02-19 08:11

I\'m handling large 64 bit unsigned integers from a JSON source which are being parsed into NSDecimalNumbers, which is apparently to \"faithfully represent arbitrary-precision n

2条回答
  •  孤街浪徒
    2021-02-19 08:52

    I've had a response from Apple on this issue via the developer forums:

    This is a standing issue with NSDecimalNumber where the simple accessors (such as [unsigned]longLongValue) go through the doubleValue accessor – this any value requiring more than 53 bits of precision will be inappropriately rounded. Feel free to Report a Bug about this issue and mention bug number 8220543.

    That said, if you are just getting 64-bit numbers from JSON, you should be able to just use NSNumber instead of NSDecimalNumber.

    So I'm solving it by changing parser from SBJson to JSONKit, which is not only much faster, it also maps numbers into NSNumber objects instead of NSDecimalNumber objects.

提交回复
热议问题