Skip to content

Commit a327f28

Browse files
committed
Released 5.0.0-alpha.1.
1 parent c5275d6 commit a327f28

27 files changed

+824
-688
lines changed

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
# 5.0.0-alpha.1
2+
The driver for this release and the breaking changes comes from:
3+
https://github.com/onepub-dev/money.dart/issues/79
4+
5+
The aim is to allow users to fully customise the group and decimal separators.
6+
We have also renamed 'scale' to 'decimalDigits' as this term is likely to be
7+
more familiar to users.
8+
9+
## breaking changes
10+
- The 'invertSeparator' argument to the Currency class has been broken out
11+
into two separate arguments 'groupSeparator' and 'decimalSeparator'.
12+
If you are using 'invertSeparator: true' then you need to replace this with
13+
```dart
14+
groupSeparator: '.',
15+
decimalSeparator: ',',
16+
```
17+
- patterns used for parsing and formatting must always use ',' for group separators
18+
and '.' for decimal separators regardless of what has been used for the
19+
groupSeparator and decimalSeparator.
20+
This allows a single pattern to be used across currencies rather than having
21+
to create a unique pattern for each currency when looking to use custom formats.
22+
23+
This means that if you have been using 'invertSeparator: true' then you will
24+
need to modifiy any custom patterns from '#.###,##' to '#,###.##'.
25+
Note the change in the separators!
26+
27+
28+
- For methods that take a 'code' it has been renamed 'isoCode' to make the
29+
correct use of the code more apparent.
30+
31+
- renamed PatterDecoder.isCode to isIsoCode
32+
- renamed CurrencyCode to CurrencyIsoCode
33+
- renamed all occurances of 'scale' to 'decimalDigits' as many people
34+
are not familiar with the concept of scale.
35+
- changed toScale on ExchangeRate members to be 'toDecimalDigits'.
36+
37+
## non-breaking changes
38+
- Fixed doco for Currencies class as it is a singleton and it's needs methods need to be called via Currencies()...
39+
140
# 4.1.0
241
- upgraded to intl 0.19
342

example/example.dart

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ void main() {
1111
/// Create money from Fixed amount
1212
1313
final fixed = Fixed.fromInt(100);
14-
Money.parse('1.23', code: 'AUD');
14+
Money.parse('1.23', isoCode: 'AUD');
1515

16-
Money.fromFixed(fixed, code: 'AUD');
16+
Money.fromFixed(fixed, isoCode: 'AUD');
1717

18-
Money.fromDecimal(Decimal.parse('1.23'), code: 'EUR');
18+
Money.fromDecimal(Decimal.parse('1.23'), isoCode: 'EUR');
1919

2020
///
2121
/// Create a money which stores $USD 10.00
@@ -24,7 +24,7 @@ void main() {
2424
/// monetary value.
2525
/// So $10.00 is 1000 cents.
2626
///
27-
final costPrice = Money.fromInt(1000, code: 'USD');
27+
final costPrice = Money.fromInt(1000, isoCode: 'USD');
2828

2929
print(costPrice);
3030
// > $10.00
@@ -42,13 +42,13 @@ void main() {
4242
/// Create a [Money] instance from a String
4343
/// using [Money.parse]
4444
///
45-
final taxPrice = Money.parse(r'$1.50', code: 'USD');
45+
final taxPrice = Money.parse(r'$1.50', isoCode: 'USD');
4646
print(taxPrice.format('CC 0.0 S'));
4747
// > US 1.50 $
4848

4949
///
5050
/// Create a [Money] instance from a String
51-
/// with an embedded Currency Code
51+
/// with an embedded Currency isoCode
5252
/// using [Currencies.parse]
5353
///
5454
/// Create a custom currency
@@ -68,7 +68,7 @@ void main() {
6868
Currencies().register(Currency.create('DODGE', 5, symbol: 'Ð'));
6969
final dodge = Currencies().find('DODGE');
7070
Money.fromNumWithCurrency(0.1123, dodge!);
71-
Money.fromNum(0.1123, code: 'DODGE');
71+
Money.fromNum(0.1123, isoCode: 'DODGE');
7272

7373
///
7474
/// Do some maths
@@ -84,7 +84,7 @@ void main() {
8484
///
8585
/// Do some custom formatting of the ouput
8686
/// S - the symbol e.g. $
87-
/// CC - first two digits of the currency code provided when creating
87+
/// CC - first two digits of the currency isoCode provided when creating
8888
/// the currency.
8989
/// # - a digit if required
9090
/// 0 - a digit or the zero character as padding.
@@ -95,7 +95,7 @@ void main() {
9595
/// Explicitly define the symbol and the default pattern to be used
9696
/// when calling [Money.toString()]
9797
///
98-
/// JPY - code for japenese yen.
98+
/// JPY - isoCode for japenese yen.
9999
/// 0 - the number of minor units (e.g cents) used by the currency.
100100
/// The yen has no minor units.
101101
/// ¥ - currency symbol for the yen
@@ -118,7 +118,10 @@ void main() {
118118
/// -> 1.000,00
119119
///
120120
final euro = Currency.create('EUR', 2,
121-
symbol: '€', invertSeparators: true, pattern: '#.##0,00 S');
121+
symbol: '€',
122+
groupSeparator: '.',
123+
decimalSeparator: ',',
124+
pattern: '#,##0.00 S');
122125

123126
final bmwPrice = Money.fromIntWithCurrency(10025090, euro);
124127
print(bmwPrice);
@@ -130,7 +133,7 @@ void main() {
130133
///
131134
132135
// 100,345.30 usd
133-
final teslaPrice = Money.fromInt(10034530, code: 'USD');
136+
final teslaPrice = Money.fromInt(10034530, isoCode: 'USD');
134137

135138
print(teslaPrice.format('###,###'));
136139
// > 100,345
@@ -142,14 +145,14 @@ void main() {
142145
// > US100,345.30
143146

144147
// 100,345.30 EUR
145-
final euroCostPrice = Money.fromInt(10034530, code: 'EUR');
146-
print(euroCostPrice.format('###.###'));
148+
final euroCostPrice = Money.fromInt(10034530, isoCode: 'EUR');
149+
print(euroCostPrice.format('###,###'));
147150
// > 100.345
148151

149-
print(euroCostPrice.format('###.###,## S'));
152+
print(euroCostPrice.format('###,###.## S'));
150153
// > 100.345,3 €
151154

152-
print(euroCostPrice.format('###.###,#0 CC'));
155+
print(euroCostPrice.format('###,###.#0 CC'));
153156
// > 100.345,30 EU
154157

155158
///
@@ -161,7 +164,7 @@ void main() {
161164
Currencies().register(jpy);
162165

163166
// use a registered currency by finding it in the registry using
164-
// the currency code that the currency was created with.
167+
// the currency isoCode that the currency was created with.
165168
final usDollar = Currencies().find('USD');
166169

167170
final invoicePrice = Money.fromIntWithCurrency(1000, usDollar!);
@@ -180,7 +183,7 @@ void main() {
180183

181184
// retrieve all registered currencies
182185
final registeredCurrencies = Currencies().getRegistered();
183-
final codes = registeredCurrencies.map((c) => c.code);
186+
final codes = registeredCurrencies.map((c) => c.isoCode);
184187
print(codes);
185188
// (USD, AUD, EUR, JPY)
186189
}

lib/money2.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
///
1010
///
1111
/// The [Currency] class allows you to define the key attributes of a currency
12-
/// such as Symbol, Code, precision and a default format.
12+
/// such as Symbol, isoCode, precision and a default format.
1313
///
1414
/// The [Money] class stores the underlying values using a BigInt. The value
1515
/// is stored using the currencies 'minor' units (e.g. cents).
@@ -33,7 +33,7 @@
3333
/// The package use the following terms:
3434
/// * Minor Units - the smallest unit of a currency e.g. cents.
3535
/// * Major Units - the integer component of a currency - e.g. dollars
36-
/// * code - the currency code. e.g. USD
36+
/// * isoCode - the currency isoCode. e.g. USD
3737
/// * symbol - the currency symbol. e.g. '$'. It should be noted that not
3838
/// every currency has a symbol.
3939
/// * pattern - a pattern used to control the display format.

lib/src/common_currencies.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class CommonCurrencies {
3838
/// Brazilian Real
3939
final Currency brl = Currency.create('BRL', 2,
4040
symbol: r'R$',
41-
invertSeparators: true,
42-
pattern: 'S0,00',
41+
groupSeparator: '.',
42+
decimalSeparator: ',',
4343
country: 'Brazil',
4444
unit: 'Real',
4545
name: 'Brazilian Real');
@@ -65,17 +65,19 @@ class CommonCurrencies {
6565
/// Czech Koruna
6666
final Currency czk = Currency.create('CZK', 2,
6767
symbol: 'Kč',
68-
invertSeparators: true,
69-
pattern: '0,00S',
68+
groupSeparator: '.',
69+
decimalSeparator: ',',
70+
pattern: '0.00S',
7071
country: 'Czech',
7172
unit: 'Koruna',
7273
name: 'Czech Koruna');
7374

7475
/// European Union Euro
7576
final Currency euro = Currency.create('EUR', 2,
7677
symbol: '€',
77-
invertSeparators: true,
78-
pattern: '0,00S',
78+
groupSeparator: '.',
79+
decimalSeparator: ',',
80+
pattern: '0.00S',
7981
country: 'European Union',
8082
unit: 'Euro',
8183
name: 'European Union Euro');
@@ -118,8 +120,9 @@ class CommonCurrencies {
118120
/// Polish Zloty
119121
final Currency pln = Currency.create('PLN', 2,
120122
symbol: 'zł',
121-
invertSeparators: true,
122-
pattern: '0,00S',
123+
groupSeparator: '.',
124+
decimalSeparator: ',',
125+
pattern: '0.00S',
123126
country: 'Polish',
124127
unit: 'Zloty',
125128
name: 'Polish Zloty');

0 commit comments

Comments
 (0)