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?

Formatting

The money class provides a simple way of formatting currency using a pattern.

When you create a Currency instance you can provide a default format pattern which is used to format a Money instance when you call Money.toString().

The CommonCurrencies have default formatters for each Currency which is consistent with that currencies standards.

In some cases you may however want to format a Money instances in a specific manner. In this case you can use:

Money.format(String pattern)

import 'package:money2/money2.dart';
     test('formatting', () {
        final usd = Currency.create('USD', 2);
        final one = Money.fromIntWithCurrency(100, usd);
        expect(one.format('S0'), equals(r'$1'));
      });
PreviousdecimalDigitsNextFormatting Patterns

Last updated 29 days ago

Was this helpful?