UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

31 lines (26 loc) 609 B
/*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ import { dividePrecision } from "./chunk-NNNPJRRQ.mjs"; import { timesPrecision } from "./chunk-I7ZFDSJ2.mjs"; import { isNumber } from "./chunk-N7YWL7WT.mjs"; // src/numberRoundPrecision.ts function roundPrecision(num, decimal) { const base = 10 ** decimal; let result = dividePrecision(Math.round(Math.abs(timesPrecision(num, base))), base); if (isNumber(num) && num < 0 && result !== 0) { result = timesPrecision(result, -1); } return result; } export { roundPrecision };