function _roundNumber()

in runtime/shared/intlNumUtils.js [276:305]


function _roundNumber(valueParam: number, decimalsParam?: number): string {
  const decimals = decimalsParam == null ? 0 : decimalsParam;
  const pow = Math.pow(10, decimals);
  let value = valueParam;
  value = Math.round(value * pow) / pow;
  value += '';
  if (!decimals) {
    return value;
  }

  // if value is small and
  // was converted to scientific notation, don't append anything
  // as we are already done
  if (value.indexOf('e-') !== -1) {
    return value;
  }

  const pos = value.indexOf('.');
  let zeros = 0;
  if (pos == -1) {
    value += '.';
    zeros = decimals;
  } else {
    zeros = decimals - (value.length - pos - 1);
  }
  for (let i = 0, l = zeros; i < l; i++) {
    value += '0';
  }
  return value;
}