Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import BigNumber from 'bignumber.js'; /** * @description Returns a fn that validates a number is within the specified decimal precision * Useful in conjunction with a form validation schema */ export function validateDecimalPrecision(allowedPrecision: number) { return (value: any) => { Iif (value === null || value === undefined) return false; // Explicit base ensures BigNumber doesn't use exponential notation // eslint-disable-next-line @typescript-eslint/no-unsafe-argument const decimals = new BigNumber(value).toString(10).split('.')[1]; return decimals === undefined || decimals.length <= allowedPrecision; }; } |