Registering a Currency
Common Currencies
Register a Currency
import 'package:money2/money2.dart';
import 'package:test/test.dart';
void main() {
test('register currency', () {
/// Create currency and replace the CommonCurrency with our
/// own one.
final usd = Currency.create('USD', 2);
Currencies().register(usd);
/// Change the registered euro currency to have 4 decimal places
/// Note: CommonCurrencies can't be changed but the registry can.
final euro = CommonCurrencies().euro.copyWith(decimalDigits: 4);
Currencies().register(euro);
final euro4 = Currencies().parse('EUR1500.0');
expect(euro4.decimalDigits, equals(4));
/// register a new currency with 8 decimals.
final doge =
Currency.create('DODG', 8, symbol: 'Ð', pattern: 'S0.00000000');
Currencies().register(doge);
// find a registered currency.
final nowUseIt = Currencies().find('DODG');
expect(nowUseIt, isNotNull);
if (nowUseIt != null) {
final cost = Money.fromIntWithCurrency(1000000000, nowUseIt);
expect(cost.toString(), equals('Ð10.00000000'));
}
});
}Last updated
Was this helpful?