money2
  • Overview
  • Common Currencies
  • Creating a Currency
  • Registering a Currency
  • Parsing
  • Find a currency
  • Default format
  • Symbols
  • Separators
    • Decimal Separator
    • Group Separator
  • Creating Money
    • Money.parse
    • Currency.parse
    • Money.from
    • Currencies.parse
    • decimalDigits
  • Formatting
    • Formatting Patterns
  • Storing and Send
  • Exchange Rates
  • Comparison
  • Currency Predicates
  • Value Sign Predicates
  • Arithmetic Operations
  • Allocation
  • Money encoding/decoding
Powered by GitBook
On this page

Was this helpful?

  1. Creating Money

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');
      });
PreviousCurrency.parseNextCurrencies.parse

Last updated 28 days ago

Was this helpful?