Money.from

The Money class allows you to create a Money instance from a variety of other types:

  • Money.fromFixed

  • Money.fromInt

  • Money.fromBigInt

  • Money.fromNum

  • Money.fromDecimal

Each of the variants have a withCurrency alternate form:

  • Money.fromFixedWithCurrency

  • Money.fromIntWithCurrency

  • Money.fromBigIntWithCurrency

  • Money.fromNumWithCurrency

  • Money.fromDecimalWithCurrency

The recommended method is to used Money.fromFixed or the `withCurrency` alternative. Using `fromFixed` then allows you to store and transmit your Money amounts without loss of precision.

Money can be instantiated by providing the amount in the minor units of the currency (e.g. cents):

 test('parse with Currency', () {
        // create one (1) australian dollar
        Money.fromFixed(Fixed.fromInt(100), isoCode: 'AUD');

        Money.parse(r'$1.00', isoCode: 'AUD');

        Money.fromFixedWithCurrency(Fixed.fromInt(100), CommonCurrencies().aud);

        Money.parseWithCurrency(r'$1.00', CommonCurrencies().aud);

        /// Create a money value of $5.10 usd from an int
        Money.fromInt(510, isoCode: 'USD');

        /// Create a money value of ¥25010 from a big int.
        Money.fromBigInt(BigInt.from(25010), isoCode: 'JPY');
      });

Last updated

Was this helpful?