UNPKG

json-schema-library

Version:

Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation

12 lines (11 loc) 350 B
/** * returns the floating point precision of a decimal number or 0 */ export function getPrecision(value: number): number { const string = `${value}`; if (string.includes("e-")) { return parseInt(string.replace(/.*e-/, "")); } const index = string.indexOf("."); return index === -1 ? 0 : string.length - (index + 1); }