// ../shared/utils/dist/src/roundValue.js
function roundValue(value, digits) {
  const v = Number(value);
  if (Number.isInteger(v)) return v;
  if (Math.abs(v) < 1) return Number(v.toPrecision(digits));
  return Number(v.toFixed(digits));
}
function roundValueAuto(value, format = false, defaultDigits = 2) {
  if (!value && value != 0) return value;
  const dp = decimalPlacesUntilFirstNonZero(value);
  const digits = Math.abs(value) > 1 ? defaultDigits : dp > 0 ? dp + 1 : defaultDigits;
  if (format) return formatValue(value, digits);
  return roundValue(value, digits);
}
function decimalPlacesUntilFirstNonZero(number) {
  const numberStr = number.toString();
  const decimalIndex = numberStr.indexOf(".");
  if (decimalIndex === -1 || decimalIndex === numberStr.length - 1) {
    return 0;
  }
  let decimalPlaces = 0;
  for (let i = decimalIndex + 1; i < numberStr.length; i++) {
    if (numberStr[i] === "0") {
      decimalPlaces++;
    } else if (numberStr[i] >= "1" && numberStr[i] <= "9") {
      break;
    }
  }
  return decimalPlaces;
}
function formatValue(value, digits) {
  const v = Number(value);
  if (Number.isInteger(v)) return v;
  const abs = Math.abs(v);
  if (abs < 1 || abs > 9999) {
    return abs > 9999 ? v.toPrecision(digits) : Number(v.toPrecision(digits));
  }
  return Number(v.toFixed(digits));
}

export {
  roundValue,
  roundValueAuto,
  decimalPlacesUntilFirstNonZero
};
//# sourceMappingURL=chunk-TLT4YIG3.js.map
