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"