Skip to main content

formatArray

FitFileViewer - API Documentation v29.4.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:37

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

options?​

Additional formatting options

separator?​

string

Custom separator for joined values

strictValidation?​

boolean

Whether to throw on invalid numbers

Returns​

any

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

Throws​

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

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"