Skip to content

Instantly share code, notes, and snippets.

@robnadin
Created December 22, 2015 12:40
Show Gist options
  • Save robnadin/6c493972153f70dea606 to your computer and use it in GitHub Desktop.
Save robnadin/6c493972153f70dea606 to your computer and use it in GitHub Desktop.

NSDecimalNumber Integer Fix

So given the decimal 109268.27107118553088 the result is:

32-bit architecture

integer: 0
int: 109268
uint: 109268
unsigned integer: 0

64-bit architecture

integer: -75199
int: 109268
uint: 109268
unsigned integer: 109268

Solution

extension NSDecimalNumber {
    
    override public var integerValue: Int {
        return Int(doubleValue)
    }
    
    override public var unsignedIntegerValue: UInt {
        return UInt(doubleValue)
    }
}

Result

integer: 109268
int: 109268
uint: 109268
unsigned integer: 109268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment