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):

// create one (1) australian dollar
Money t1 = Money.fromFixed(Fixed.fromInt(100, scale: 2), code: 'AUD');

Money t2 = Money.parse(r'$1.00', code: 'AUD');

Money t3 = Money.fromFixedWithCurrency(Fixed.fromInt(100, scale: 2), 
    currency: CommonCurrencies().aud);
    
Money t4 = Money.parse(r'$1.00',  currency: CommonCurrencies().aud);
    

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

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

Last updated