Skip to content

This site describes solve-engine as it is on main: 2.43.0, which npm does not have yet. npm installs 2.40.0, so a page may show an answer that version does not give yet.

autoFormatIntegerOrFloat

function autoFormatIntegerOrFloat(
number,
decimalPlaces?,
includeThousandSeparators?,
numberLocale?,
trimTrailingZeros?
): string;

Defined in: packages/engine/src/utilities/Number.ts:293

Format number for display, branching on whether it’s a whole number: integers are always rendered with zero decimal places (never padded to decimalPlaces), while non-integers are rendered with up to decimalPlaces fractional digits, padded with zeros to that many unless trimTrailingZeros is set. includeThousandSeparators controls whether groups are separated (e.g. "1,234") per numberLocale.

ParameterTypeDefault valueDescription
numbernumberundefinedThe value to format.
decimalPlacesnumber2Max fractional digits for non-integer values (default 2).
includeThousandSeparatorsbooleanfalseWhether to group digits (default false).
numberLocalestring"en-US"Intl/toLocaleString locale to format with (default “en-US”).
trimTrailingZerosbooleanfalseWhether a fraction drops the zeros that only pad it out to decimalPlaces, so 1.5 is 1.5 rather than 1.50 (default false).

string