money2 1.0.3 copy "money2: ^1.0.3" to clipboard
money2: ^1.0.3 copied to clipboard

outdated

Simple to use Money and Currency classes. Provides Money and Currency classes with fixed precision maths operations and a nice Money formatter.

example/example.dart

import 'package:money2/money2.dart';

void main() {
  final usd = Currency.create('USD', 2);

  final Currency aud =
      Currency.create('AUD', 2, symbol: '\$', pattern: 'S0.00');
  Money audMoney = Money.fromInt(500, aud);
  audMoney.toString();
  // > $5.00

  final Currency jpy = Currency.create('JPY', 0, symbol: '¥', pattern: 'S0');
  Money jpyMoney = Money.fromInt(500, jpy);
  jpyMoney.toString();
  // > ¥500

  final Currency euro = Currency.create('EUR', 2,
      symbol: '€', invertSeparators: true, pattern: "S0,00");

  Money costPrice = Money.fromInt(10034530, usd); // 100,345.30 usd

  costPrice.format("###,###");
  // > 100,345

  costPrice.format("S###,###.##");
  // > $100,345.3

  costPrice.format("CC###,###.#0");
  // > US100,345.30

  Money euroCostPrice = Money.fromInt(10034530, euro); // 100,345.30 EUR

  euroCostPrice.format("###.###");
  // > 100.345

  euroCostPrice.format("S###.###,##");
  // > €100.345,3

  euroCostPrice.format("CC###.###,#0");
  // > EU100,345,30

  // Make the currencies available globally by registering them with the [Currencies] singleton factory.
  Currencies().register(usd);
  Currencies().register(aud);
  Currencies().register(euro);
  Currencies().register(jpy);

  // use a registered currency.
  Currency aussieDollar = Currencies().find("AUD");

  Money invoicePrice = Money.fromInt(1000, aussieDollar);
  invoicePrice.format("SCCC 0.00");
  // $AUD 10.00


  // Do some maths
  Money taxInclusivePrice = invoicePrice * 1.1;
  taxInclusivePrice.toString();
  // $11.00

  taxInclusivePrice.format("SCCC 0.00");
  // $AUD 11.00

}
171
likes
0
pub points
96%
popularity

Publisher

verified publisheronepub-web.flutter-io.cn

Simple to use Money and Currency classes. Provides Money and Currency classes with fixed precision maths operations and a nice Money formatter.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

intl

More

Packages that depend on money2