Arithmetic Operations
The Money class is immutable, so each operation returns a new Money instance.
Whilst money does support a number of arithmetic operations that take a double as the operator this is STRONGLY DISCOURAGE. Doubles are imprecise and will introduce rounding errors.
Where ever possible used the methods that take a Fixed, Int or BigInt.
MultiplyByFixed
Multiply a Money instance by a Fixed instance.
Multiply by num (double or int)
The '*' operator takes a num and converts it to a Fixed value with 16 decimal places. However the scale of the result is dictated by the Money instance passed to the '*' operator.
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
Was this helpful?