Money.fromInt constructor

Money.fromInt(
  1. int minorUnits, {
  2. required String isoCode,
  3. int? decimalDigits,
})

Money.fromInt


Creates an instance of Money from an integer.

minorUnits - the no. minorUnits of the currency, e.g (cents). isoCode - the currency isoCode of the minorUnits. This must be either one of the CommonCurrencies or a currency you have registered via Currencies.register. decimalDigits - the number of decimal digits to store.

Throws an UnknownCurrencyException if the isoCode is not a registered isoCode.

Implementation

/// Creates an instance of [Money] from an integer.
///
/// [minorUnits] - the no. minorUnits of the [currency], e.g (cents).
/// [isoCode] - the currency isoCode of the [minorUnits].
///     This must be either one of the [CommonCurrencies] or a currency
/// you have registered via [Currencies.register].
/// [decimalDigits] - the number of decimal digits to store.
///
/// Throws an [UnknownCurrencyException] if the [isoCode] is not a registered
/// isoCode.
factory Money.fromInt(int minorUnits,
    {required String isoCode, int? decimalDigits}) {
  final currency = Currencies().find(isoCode);
  if (currency == null) {
    throw UnknownCurrencyException(isoCode);
  }

  return Money.fromIntWithCurrency(minorUnits, currency,
      decimalDigits: decimalDigits);
}