Why NSDecimalNumber(string:"2175613.285964774433431797660").intValue
= 0
NSDecimalNumber(string:"2175613.285964774433431797660").int32Value
= 2175613
NSDecimalNumber(string:"2175613.285964774433431797660").int64Value
= 0
Who can help me?
Apple M1
Mac OS Ventura 13.0
Xcode 14.1
let a = NSDecimalNumber(string: "2175613.285964774433431797660188672").intValue
// a == 0 is true
This problem caused our users’ wallet balances to clear directly to zero.
2
Answers
Looks like whenever the decimal significand overflows 64-bit Integer the result is unpredictable regardless of the decimal exponent value. One option to solve your issue is to round your decimal number before converting it to integer. You can overcome this issue as follow:
It looks like you’re having issues with converting strings to decimals.
Keep in mind that users may have different device locales, so an incorrect decimal separator could result in the wrong output.