Arithmetic Operations
The Money class is immutable, so each operation returns a new Money instance.
Money uses fixed scale (no. of decimals) mathemtatics operations which can lead to some expected results.
The problem with the above equation is that `amount` has a scale of 0. As we don't know the scale of the double (0.4) we use the scale of the amount. The resuls in 0.4 being rounded down to zero.
The correct way to handle this is to first convert the double to a Fixed instance with the desired scale.
Money
provides the following arithmetic operators:
unary
-()
+(Money)
-(Money)
*(num)
/(num)
Operators +
and -
must be used with operands in same currency, otherwise ArgumentError
will be thrown.
Operators *
, /
receive a num
as the second operand. Both operators use schoolbook rounding to round result up to a minorUnits of a currency.
Last updated