matt2405 matt2405 - 1 year ago 128
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

Answer Source

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) =
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download