QuantityFormat class
Allows a Quantity to be formatted.
See UnitOfMeasurementFormat for general notes on the pattern syntax, which you can combine with the QuantityUnit pattern specifiers as required:
Unit | Specifier |
---|---|
one | U |
thousand | K |
million | M |
billion | B |
trillion | T |
final quantity = 42.thousand();
// '42K'
final result1 = QuantityFormat().format(quantity);
// '42 thousand'
final result2 = QuantityFormat(pattern: '0.## U').format(quantity);
// '42,000'
final result3 = QuantityFormat(pattern: '###,##0.## u:U').format(quantity);
See also:
- Inheritance
-
- Object
- UnitOfMeasurementFormat<
Quantity, QuantityUnit> - QuantityFormat
Constructors
-
QuantityFormat({String pattern = '0.##${UnitOfMeasurementFormat.valueUnitSymbolFormatSpecifier}', Set<
QuantityUnit> permissibleValueUnits = QuantityUnits.all, String? locale})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- locale → String?
-
The locale to use when formatting values.
finalinherited
- pattern → String
-
The pattern that indicates the desired output when formatting input values.
finalinherited
-
permissibleRateUnits
→ Set<
RateUnit> -
finalinherited
-
permissibleValueUnits
→ Set<
QuantityUnit> -
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
format(
Quantity input) → String -
Formats
input
according to the pattern and locale of this format.inherited -
getLargestUnit(
Quantity input) → QuantityUnit -
Determines the largest denomination of unit in
input
that has a value of at least1
.override -
getPatternSpecifierFor(
QuantityUnit valueUnit) → String -
Gets the pattern specifier for the given value unit.
inherited
-
getPermissibleRateUnits(
) → Set< RateUnit> -
Gets a set of permissible
RateUnit
values.inherited -
getPermissibleValueUnits(
) → Set< QuantityUnit> -
Gets a set of permissible
TUnit
values.inherited -
getUnitName(
QuantityUnit unit, String locale) → String -
Gets the a
unit
name in the givenlocale
.inherited -
getUnitQuantity(
Quantity input, QuantityUnit unit) → Rational -
Determines how many units of
unit
theinput
contains, including any fractional portion.override -
getUnitSymbol(
QuantityUnit unit, String locale) → String -
Gets the a
unit
symbol in the givenlocale
.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pluralizeValueUnits(
String locale) → bool -
Determines whether value units should be pluralized. Defaults to
true
.override -
scaleToRateUnit(
Quantity input, RateUnit rateUnit) → Quantity -
Scales
input
, which is assumed to be a rated unit of measurement, so that its rate israteUnit
.override -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited