ExchangeRate class
When defining an exchange rate we need to specify the conditions under which the exchange is calculated.
An ExchangeRate allows us to convert a Money instance from one Currency to another.
e.g.
AUD 1.00 = USD 65c.
Constructors
- ExchangeRate.fromBigInt(BigInt exchangeRateMinorUnits, {required int decimalDigits, required CurrencyIsoCode fromIsoCode, required CurrencyIsoCode toIsoCode})
-
Create an exchange rate from an BigInt holding minor units
to the provided
decimalDigits
.factory - ExchangeRate.fromBigIntWithCurrency(BigInt exchangeRateMinorUnits, {required int decimalDigits, required Currency fromCurrency, required Currency toCurrency, int? toDecimalDigits})
- ExchangeRate.fromFixed(Fixed exchangeRate, {required CurrencyIsoCode fromIsoCode, required CurrencyIsoCode toIsoCode, int? toDecimalDigits})
-
Create an exchange rate from a Fixed decimal.
factory
- ExchangeRate.fromFixedWithCurrency(Fixed exchangeRate, {required Currency fromCurrency, required Currency toCurrency, int? toDecimalDigits})
- Create an exchange rate from a Fixed decimal.
- ExchangeRate.fromMinorUnits(int exchangeRateMinorUnits, {required int decimalDigits, required CurrencyIsoCode fromCode, required CurrencyIsoCode toCode, int? toDecimalDigits})
-
Create an exchange rate from an integer holding minor units
to the provided number of
decimalDigits
.factory - ExchangeRate.fromMinorUnitsWithCurrency(int exchangeRateMinorUnits, {required int decimalDigits, required Currency fromCurrency, required Currency toCurrency, int? toDecimalDigits})
-
Create an exchange rate from an integer holding minor units
to the provided
decimalDigits
. - ExchangeRate.fromNum(num exchangeRate, {required int decimalDigits, required CurrencyIsoCode fromCode, required CurrencyIsoCode toCode, int? toDecimalDigits})
-
Create an exchange rate from an integer or decimal holding major units
factory
- ExchangeRate.fromNumWithCurrency(num rateAsNum, {required int decimalDigits, required Currency fromCurrency, required Currency toCurrency, int? toDecimalDigits})
- Create an exchange rate from an integer or decimal holding major units
Properties
- exchangeRate ↔ Fixed
-
The exchange rate
latefinal
- fromCurrency ↔ Currency
-
The Currency that we are converting from.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- toCurrency ↔ Currency
-
After the exchange rate is applied this
will the resulting Currency of the returned Money
latefinal
- toDecimalDigits → int?
-
The number of decimal digigs of the resulting Currency
If not passed then we use the default decimalDigits
of the toCurrency
final
Methods
-
applyInverseRate(
Money amount) → Money -
Applies the exchange rate in the reverse direction.
The Currency of the
amount
must be the same as the toCurrency otherwise a MismatchedCurrencyException is thown. -
applyRate(
Money amount) → Money -
Apply the exchange rate to
amount
and return a new Money in the toCurrency. -
format(
String pattern) → String -
Formats the exchangeRate using the given
pattern
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited