feetToString static method
Formats feet as a human-readable string.
With showInches (default) the fractional part is rendered as inches,
e.g. "5 feet 6 inches" or "5 ft 6 in" with useAbbreviations. Without
it, a single decimal value is shown, e.g. "5.5 feet".
Contract for edge cases:
- Non-finite input (NaN/∞) skips the inches decomposition (which would
throw on
floor()) and renders the value alone, e.g."NaN feet". - Rounding inches can reach 12 at the chosen precision; this carries into
whole feet so the output is never
"5 feet 12 inches". - Negative heights render with a leading sign on the feet, e.g.
"-5 feet 6 inches", rather than lettingfloor()push inches positive.
Example:
LengthConversionUtils.feetToString(5.5); // '5 feet 6 inches'
LengthConversionUtils.feetToString(5.5, useAbbreviations: true); // '5 ft 6 in'
LengthConversionUtils.feetToString(5.5, showInches: false); // '5.5 feet'
Audited: 2026-06-12 11:26 EDT
Implementation
@useResult
static String feetToString(
double feet, {
bool useAbbreviations = false,
bool showInches = true,
int decimalPlaces = 2,
}) {
final String ftLabel = useAbbreviations ? 'ft' : 'feet';
// NaN and infinity have no integer floor and would throw in the inches
// decomposition. Render the value alone instead; the formatter handles them.
if (!showInches || !feet.isFinite) {
return '${feet.formatDouble(decimalPlaces, showTrailingZeros: false)} $ftLabel';
}
return _feetInchesString(
feet,
useAbbreviations: useAbbreviations,
decimalPlaces: decimalPlaces,
);
}