Money.fromNumWithCurrency constructor
Creates an instance of Money from a num holding the monetary value.
Unlike Money.fromBigInt the amount is in dollars and cents (not just cents). This means that you can intiate a Money value from a double or int as follows:
Money buyPrice = Money.from(10);
print(buyPrice.toString());
> $10.00
Money sellPrice = Money.from(10.50);
print(sellPrice.toString());
> $10.50
NOTE: be very careful using doubles to transport money as you are guarenteed to get rounding errors!!! You should use a String and Money.parse().
amount
- the monetary value.
currency
- the currency of the amount
.
decimalDigits
- allows you to set an alternate number of decimalDigits
If not provided then currency
's decimalDigits
are used.
Implementation
factory Money.fromNumWithCurrency(num amount, Currency currency,
{int? decimalDigits}) =>
Money._from(
Fixed.fromNum(amount, scale: decimalDigits ?? currency.decimalDigits),
currency);