Money class
A Money is a value object that represents an amount and an associated currency. Amounts either represent a real value (e.g. -$1927.10, ¥10, £1.56, 0.00kr.) or are unavailable (e.g. have no numerical value).
☞ In many financial applications, host systems can be unavailable throughout the day due to batch jobs running etc, and for this reason, amounts have notion of being unavailable.
Money objects can be compared, hashed, added and subtracted. Using a MoneyFormatter class, Money objects can be converted to and from strings.
- Implemented types
- Available Extensions
Constructors
- Money.decimal(Decimal amount, Currency currency)
-
Initializes a Money object with an
amount
represented by a Decimal.currency
metadata is used to format, parse and operate upon an amount. - Money.double(double amount, Currency currency)
-
Initializes a Money object with an
amount
represented by a double (double.nan indicates an unavailable amount). Due to binary approximation errors, this constructor should be used sparingly, and the Decimal or String constructors preferred.currency
metadata is used to format, parse and operate upon an amount. - Money.string(String amount, Currency currency)
-
Initializes a Money object with an amount represented by a String. If the
amount cannot be converted to a string, then the Money object will be
represented as unavailable. See MoneyFormatter for string formats of Money
amounts.
amount
represented as a String, whitespace is removed from the beginning and end of the string before parsing.currency
metadata is used to format, parse and operate upon an amount. - Initializes a Money object with an unavailable amount.
Properties
- currency → Currency
-
The metadata used to format, parse and operate upon an amount.
no setter
- hashCode → int
-
Hashes the essential components of this Money object.
no setteroverride
- isNegative → bool
-
Returns true if the money amount is negative. Unavailable amounts
always return false.
no setter
-
Money objects can either be real or unavailable. This property returns
true if the amount is unavailable.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
accessibilityText(
) → String - Returns the textual string used for voiceover of an amount or '' if unavailable. e.g. '-$523.84 NZD' is returned as 'new zealand negative five hundred and twenty three dollars and eighty four cents'. See MoneyFormatter accessibilityText(amount, negative, prefix) for more details.
-
compareTo(
dynamic other) → int -
Compares two Money objects for order using the currency and amount.
Currencies are compared first in ascending order e.g. (AUD < NZD),
followed by amounts. If result is 0, then the currency and amounts match.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDecimal(
) → Decimal? - The amount of the Money object represented as a Decimal or null if unavailable.
-
toDouble(
) → double - The amount of the Money object represented as a double or double.nan if unavailable. Due to binary approximation errors, this method should be used sparingly, and the toDecimal() or toString() methods preferred.
-
toString(
{bool symbols = false, bool grouping = false, bool negative = true}) → String -
The amount of the Money object represented as a String. By default the
returned string is formatted without prefix or suffix or grouping
separators. e.g. '-2402.19'.
override
Operators
-
operator ==(
Object other) → bool -
Checks for equality between the two Money objects. The currency and
amounts must match exactly.
override