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