From 2ce41bf9afd049473ce38c4bf1804ab174026e2b Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Fri, 4 Oct 2024 11:53:55 +0700 Subject: [PATCH] feat: add util calculate with precision --- src/utils/arithmetic.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/utils/arithmetic.ts diff --git a/src/utils/arithmetic.ts b/src/utils/arithmetic.ts new file mode 100644 index 00000000..4f48f2d0 --- /dev/null +++ b/src/utils/arithmetic.ts @@ -0,0 +1,4 @@ +export function precisionRound(number: number, precision = 2) { + var factor = Math.pow(10, precision); + return Math.round(number * factor) / factor; +}