outputText method
void
outputText(
- StringBuffer buffer, {
- UncertaintyFormat uncertFormat = UncertaintyFormat.none,
- bool symbols = true,
- NumberFormat? numberFormat,
Appends a String representation of this Quantity to the buffer
using the preferred units and number format. If no preferred units have
been specified, then MKS units are used. Uncertainty in the value of the
Quantity is optionally shown as a plus/minus value in the same units.
Implementation
void outputText(StringBuffer buffer,
{UncertaintyFormat uncertFormat = UncertaintyFormat.none,
bool symbols = true,
NumberFormat? numberFormat}) {
if (preferredUnits != null) {
final val = preferredUnits!.fromMks(mks);
final nf = numberFormat ?? NumberFormatSI();
// Format the number.
buffer.write(nf.format(val));
// Uncertainty.
if (_ur != 0 && uncertFormat != UncertaintyFormat.none) {
final uncert = preferredUnits != null
? standardUncertainty.valueInUnits(preferredUnits).toDouble()
: standardUncertainty.mks.toDouble();
if (uncertFormat == UncertaintyFormat.parens) {
buffer.write('(${nf.format(uncert)})');
} else if (uncertFormat == UncertaintyFormat.plusMinus) {
final unicode = nf is NumberFormatSI && nf.unicode == true;
buffer.write(' ${unicode ? '\u{00b1}' : '+/-'} ${nf.format(uncert)}');
}
}
// Get the units string (singular or plural, as appropriate).
String unitStr;
if (symbols) {
unitStr = preferredUnits!.getShortestName(val.abs() <= 1.0);
} else {
if (val.abs() <= 1.0) {
unitStr = preferredUnits!.singular;
} else {
unitStr = preferredUnits!.name;
}
}
if (!(unitStr == '1')) {
buffer
..write(' ')
..write(unitStr);
}
} else {
// Couldn't find any preferred units.
buffer
..write(mks)
..write(' [MKS]');
}
}