UNPKG

shown

Version:

Statically-generated, responsive charts, without the need for client-side Javascript.

22 lines (18 loc) 469 B
import { DEFAULT_PRECISION } from "./constants.js" import toPrecision from "./to-precision.js" import { abs } from "./math.js" /** * Counts the number of decimal places specified by a number * @private * @param {number} value * @returns {number} decimals places */ export default (n, precision = DEFAULT_PRECISION) => { let count = 0 n = abs(n) while (toPrecision(n % 1, precision) > 0 && count < precision) { count++ n *= 10 } return count }