All files / platform/ui/src/utils getMaxDigits.ts

16.66% Statements 1/6
0% Branches 0/5
0% Functions 0/1
16.66% Lines 1/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20            34x                          
/**
 * Calculates the maximum number of digits required to display a value based on the maximum value and step size.
 * @param maxValue - The maximum value to display.
 * @param step - The step size between values.
 * @returns The maximum number of digits required to display a value.
 */
const getMaxDigits = (maxValue: number, step: number) => {
  Iif (step <= 0) {
    throw new Error('Step should be greater than zero');
  }
 
  // Get the number of integer digits for maxValue
  const integerDigits = maxValue.toString().split('.')[0].length;
  const decimalDigits = step % 1 === 0 ? 0 : step.toString().split('.')[1].length;
 
  return integerDigits + (decimalDigits ? decimalDigits + 1 : 0);
};
 
export default getMaxDigits;