UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

15 lines (12 loc) 472 B
import { stripPrecision } from './chunk-GPTFO2E2.mjs'; import { digitLengthPrecision } from './chunk-HHTSEVTB.mjs'; // 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); } export { float2FixedPrecision };