Skip to content

This site describes solve-engine 2.44.0, the version npm installs.

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.
decimalPlaces?number2Max fractional digits for non-integer values (default 2).
includeThousandSeparators?booleanfalseWhether to group digits (default false).
numberLocale?string"en-US"Intl/toLocaleString locale to format with (default “en-US”).
trimTrailingZeros?booleanfalseWhether 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