Skip to main content

formatArray

FitFileViewer - API Documentation v30.0.1


FitFileViewer - API Documentation / utils/formatting/formatters/formatUtils / formatArray

Function: formatArray()

formatArray<T>(val: T, digits?: 2, options?: FormatArrayOptions | null | undefined): string | T

Defined in: utils/formatting/formatters/formatUtils.ts:35

Formats an array or a comma-separated string of numbers.

Arrays are rounded and then parsed back to numbers before joining, preserving the legacy behavior that removes trailing zeroes. Comma-separated strings use toFixed, preserving fixed decimal places.

Type Parameters​

T​

T

Parameters​

val​

T

Value to format.

digits?​

2 = FORMATTING_CONSTANTS.DEFAULT_DECIMAL_DIGITS

Decimal digits to use for numeric values.

options?​

FormatArrayOptions | null | undefined

Formatting options.

Returns​

string | T

Formatted values, or the original value when it is not processable.

Example​

FormatArray([1.234, 2.567]); // "1.23, 2.57"
formatArray("1.234,2.567", 1); // "1.2, 2.6"

Throws​

Error when strict validation is enabled and a value is invalid.