MoneyFormatter class
A concrete implementation of a NSFormatter that creates, interprets, and validates the textual representation of money amounts.
NZD formatting examples: Parsing examples: nan -> '' '', 'abc', '¥0' -> nan 0 -> '$0.00' '$0.00' -> 0.00 1234.56 -> '$1,234.56' '1234.56' -> 1234.56 -1234.56 -> '-$1,234.56' '-$1,234.56' -> -1234.56
JPY Formatting examples: Parsing examples: nan -> '' '', 'abc', '$0.00' -> nan 0 -> '¥0' '¥0' -> 0 1234 -> '¥1,234' '1234' -> 1234 -1234 -> '¥1,234' '-¥1,234' -> -1234
Formatted textual representations of money amounts are optimized for english locales, and for UX reasons, thousands grouping characters are always represented with a comma character ',' and decimal place separators are always represented with a full stop character '.' (regardless of currency).
- Available Extensions
Constructors
- MoneyFormatter(Currency currency)
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
format(
Decimal? amount, {bool symbols = true, bool grouping = true, bool negative = true}) → String -
Formats the decimal
amount
using the currency object attached to the MoneyFormatter instance and returns the textual representation or '' if the amount is unavailable.amount
for which a textual representation is returned.symbols
specify true to prepend any symbol prefix or append any symbol suffix as specified by the currency object's symbolPrefix and symbolSuffix properties.grouping
specify true to separate groups of digits using ',' character.negative
specify true to prepend a negative sign if the amount is negative. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
parse(
String amount) → Decimal -
Parses the string for an
amount
using the currency object attached to the MoneyFormatter instance. If the string was parsed correctly, then a Decimal is returned with the amount set correctly. If the string failed to be parsed, then a MoneyParseException is thrown, with the message of the string set to one of the following: -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- defaultAccessibilityCurrency ↔ Currency
-
By default, all accessibility text output from accessibilityText
(amount, negative) will have the currencies accessibility prefix
prepended. If the currencies accessibility prefix is equal to the
defaultAccessibilityCurrency's prefix, then the prefix will not be
appended. Most financial apps have the notion of domestic currency and
foreign currencies, it is useful in this situation to only append the
prefix for foreign currencies, not to the domestic currency. The
default defaultAccessibilityCurrency is set to NZD.
getter/setter pair