Money.fromDecimal constructor

Money.fromDecimal(
  1. Decimal amount, {
  2. required String isoCode,
  3. int? decimalDigits,
})

Creates a Money from a Decimal amount.

The amount's decimal digits are adjusted to match the currency selected via isoCode. If isoCode isn't a valid currency then an UnknownCurrencyException is thrown.

Implementation

factory Money.fromDecimal(Decimal amount,
    {required String isoCode, int? decimalDigits}) {
  final currency = Currencies().find(isoCode);
  if (currency == null) {
    throw UnknownCurrencyException(isoCode);
  }

  return Money.fromDecimalWithCurrency(amount, currency,
      decimalDigits: decimalDigits);
}