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:
@ -116,7 +116,10 @@ export const useGlobalStore = defineStore('globalStore', () => {
|
|||||||
var val: string
|
var val: string
|
||||||
var opt: Record<string, any> = {}
|
var opt: Record<string, any> = {}
|
||||||
if (prec) {
|
if (prec) {
|
||||||
if (prec) opt.minimumFractionDigits = prec
|
if (prec) {
|
||||||
|
opt.minimumFractionDigits = prec
|
||||||
|
opt.maximumFractionDigits = prec
|
||||||
|
}
|
||||||
if (curr) {
|
if (curr) {
|
||||||
opt.style = 'currency'
|
opt.style = 'currency'
|
||||||
opt.currency = curr
|
opt.currency = curr
|
||||||
@ -130,6 +133,9 @@ export const useGlobalStore = defineStore('globalStore', () => {
|
|||||||
return String(val)
|
return String(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const roundMoney = (value: number): number =>
|
||||||
|
Math.round((value + Number.EPSILON) * 100) / 100
|
||||||
|
|
||||||
const floatEnLocale = (num: number | string): string => {
|
const floatEnLocale = (num: number | string): string => {
|
||||||
return num.toString().replace('.', '').replace(',', '.')
|
return num.toString().replace('.', '').replace(',', '.')
|
||||||
}
|
}
|
||||||
@ -196,6 +202,7 @@ export const useGlobalStore = defineStore('globalStore', () => {
|
|||||||
docFormats,
|
docFormats,
|
||||||
allowFormats,
|
allowFormats,
|
||||||
toTrLocale,
|
toTrLocale,
|
||||||
|
roundMoney,
|
||||||
floatEnLocale,
|
floatEnLocale,
|
||||||
trToLower,
|
trToLower,
|
||||||
trToEngLower,
|
trToEngLower,
|
||||||
|
|||||||
Reference in New Issue
Block a user