'use strict';

/*!
 * @techmely/utils
 * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
 * MIT Licensed
 */


// src/numberDigitLengthPrecision.ts
function digitLengthPrecision(num) {
  const eSplit = num.toString().split(/[eE]/);
  const len = (eSplit[0].split(".")[1] || "").length - +(eSplit[1] || 0);
  return len > 0 ? len : 0;
}

// src/numberStripPrecision.ts
function stripPrecision(num, precision = 15) {
  return +parseFloat(Number(num).toPrecision(precision));
}

// src/numberFloat2FixedPrecision.ts
function float2FixedPrecision(num) {
  if (num.toString().indexOf("e") === -1) {
    return Number(num.toString().replace(".", ""));
  }
  const dLen = digitLengthPrecision(num);
  const powDLen = 10 ** dLen;
  return dLen > 0 ? stripPrecision(Number(num) * powDLen) : Number(num);
}

exports.float2FixedPrecision = float2FixedPrecision;
