From bec6171a4564bb92c3620d59338b8d2068eb32ae Mon Sep 17 00:00:00 2001 From: burakovec Date: Mon, 20 Jul 2026 09:57:28 +0300 Subject: [PATCH] Enhance globalStore by adding maximumFractionDigits option for currency formatting and introducing roundMoney utility function for precise monetary rounding. This improves the handling of currency values and ensures consistent formatting across the application. --- src/stores/globalStore.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stores/globalStore.ts b/src/stores/globalStore.ts index 6b9f278..bf6ec84 100644 --- a/src/stores/globalStore.ts +++ b/src/stores/globalStore.ts @@ -116,7 +116,10 @@ export const useGlobalStore = defineStore('globalStore', () => { var val: string var opt: Record = {} if (prec) { - if (prec) opt.minimumFractionDigits = prec + if (prec) { + opt.minimumFractionDigits = prec + opt.maximumFractionDigits = prec + } if (curr) { opt.style = 'currency' opt.currency = curr @@ -130,6 +133,9 @@ export const useGlobalStore = defineStore('globalStore', () => { return String(val) } + const roundMoney = (value: number): number => + Math.round((value + Number.EPSILON) * 100) / 100 + const floatEnLocale = (num: number | string): string => { return num.toString().replace('.', '').replace(',', '.') } @@ -196,6 +202,7 @@ export const useGlobalStore = defineStore('globalStore', () => { docFormats, allowFormats, toTrLocale, + roundMoney, floatEnLocale, trToLower, trToEngLower,