Skip to main content

formatArray

FitFileViewer - API Documentation v29.9.0


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

Function: formatArray()

formatArray(val: any, digits?: number, options?: { separator?: string; strictValidation?: boolean; }): any

Defined in: utils/formatting/formatters/formatUtils.js:45

Formats an array or a comma-separated string of numbers to a string with each number rounded to a specified number of decimal digits.

Parameters​

val​

any

The array of numbers, comma-separated string of numbers, or other value to format

digits?​

number = FORMATTING_CONSTANTS.DEFAULT_DECIMAL_DIGITS

The number of decimal digits to round each number to. Default is 2

options?​

Additional formatting options. Default is {}

separator?​

string

Custom separator for joined values. Default is ", "

strictValidation?​

boolean

Whether to throw on invalid numbers. Default is true

Returns​

any

The formatted string of numbers, or the original value if not processable

Examples​

// Format array of numbers
formatArray([1.234, 2.567, 3.891]); // "1.23, 2.57, 3.89"
// Format comma-separated string
formatArray("1.234,2.567,3.891", 1); // "1.2, 2.6, 3.9"
// With custom options
formatArray([1.234, 2.567], 3, { separator: " | " }); // "1.234 | 2.567"

Throws​

If strictValidation is true and any value cannot be converted to a number