money2
Search…
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):
1
// create one (1) australian dollar
2
Money t1 = Money.fromFixed(Fixed.fromInt(100, scale: 2), code: 'AUD');
3
4
Money t2 = Money.parse(r'$1.00', code: 'AUD');
5
6
Money t3 = Money.fromFixedWithCurrency(Fixed.fromInt(100, scale: 2),
7
currency: CommonCurrencies().aud);
8
9
Money t4 = Money.parse(r'$1.00', currency: CommonCurrencies().aud);
10
11
12
// Create a money value of $5.10 usd from an int
13
Money fiveDollars = Money.fromInt(510, 'USD');
14
15
// Create a money value of ¥25010 from a big int.
16
Money bigDollars = Money.fromBigInt(BigInt.from(25010), 'JPY');
Copied!
Copy link