matt2405 matt2405 - 7 months ago 71
Swift Question

Subtracting NSDecimalNumber swift?

I want to subtract one NSDecimalNumber from another simply. For whatever reason, this is not working, and the first NSDecimalNumber is not updating.

Here is my code.

func updateTotal(itemAmount amount: NSDecimalNumber) {
print("before: \(, amount: \(amount)")
print("after: \(")

Both before and after are not affected by the subtraction. I am using swift 2.0


This is because decimalNumberBySubtracting(amount) returns a new value, which your code ignores:

let res =
print("after: \(res)")

If you would like to modify, you can assign it back (assuming that it is a var) =