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.

This commit is contained in:
burakovec
2026-07-20 09:57:28 +03:00
parent dfad5a41c8
commit bec6171a45

View File

@ -116,7 +116,10 @@ export const useGlobalStore = defineStore('globalStore', () => {
var val: string
var opt: Record<string, any> = {}
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,