Money.fromBigInt constructor

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

Money.fromBigInt


Creates an instance of Money from an amount represented by minorUnits which is in the minorUnits of the currency, e.g (cents).

e.g. USA dollars with 2 decimal places.

final usd = Currency.create('USD', 2);

500 cents is $5 USD. let fiveDollars = Money.fromBigInt(BigInt.from(500), usd);

isoCode - the currency isoCode of the minorUnits. This must be either one of the CommonCurrencies or a currency you have registered via Currencies.register. Throws an UnknownCurrencyException if the isoCode is not a registered isoCode.

Implementation

/// Creates an instance of [Money] from an amount represented by
/// [minorUnits] which is in the minorUnits of the [currency], e.g (cents).
///
/// e.g.
/// USA dollars with 2 decimal places.
///
/// final usd = Currency.create('USD', 2);
///
/// 500 cents is $5 USD.
/// let fiveDollars = Money.fromBigInt(BigInt.from(500), usd);
///
/// [isoCode] - the currency isoCode of the [minorUnits]. This must be
/// either one of the [CommonCurrencies] or a currency you have
/// registered via [Currencies.register].
/// Throws an [UnknownCurrencyException] if the [isoCode] is not a registered
/// isoCode.
factory Money.fromBigInt(BigInt minorUnits,
    {required String isoCode, int? decimalDigits}) {
  final currency = Currencies().find(isoCode);
  if (currency == null) {
    throw UnknownCurrencyException(isoCode);
  }

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