From 58246805d5f5d33ec43e88eca01acefa7dfd9777 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 08 十月 2026 20:54:05 +0800
Subject: [PATCH] fix: 小数点保存两位
---
src/utils/numberFormat.js | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/utils/numberFormat.js b/src/utils/numberFormat.js
index 50175f0..2913a07 100644
--- a/src/utils/numberFormat.js
+++ b/src/utils/numberFormat.js
@@ -1,6 +1,9 @@
/** 閲戦绫诲瓧娈甸粯璁ゆ渶澶у皬鏁颁綅鏁� */
export const AMOUNT_DECIMAL_SCALE = 6
+/** 閲戦锛堝厓锛夐粯璁ゅ睍绀哄皬鏁颁綅鏁� */
+export const MONEY_DECIMAL_SCALE = 2
+
/**
* 鏍煎紡鍖栨暟瀛楋細鏈�澶氫繚鐣� scale 浣嶅皬鏁帮紝骞跺幓闄ゆ湯灏惧浣欑殑 0
*/
@@ -25,6 +28,11 @@
return formatDecimal(cellValue)
}
+/** el-table-column formatter锛氶噾棰濓紙鍏冿級鍒楋紝鏈�澶氫繚鐣� 2 浣嶅皬鏁� */
+export function moneyAmountFormatter(row, column, cellValue) {
+ return formatDecimal(cellValue, MONEY_DECIMAL_SCALE)
+}
+
/** 璁$畻鍚庝繚鐣欐寚瀹氫綅灏忔暟 */
export function roundAmount(value, scale = AMOUNT_DECIMAL_SCALE) {
if (value === null || value === undefined || value === '') {
@@ -38,10 +46,14 @@
}
/** 鏋勫缓 summarizeTable 閲戦鍒楁牸寮忛厤缃� */
-export function buildAmountSummaryFormat(fields, extraFormat = {}) {
+export function buildAmountSummaryFormat(
+ fields,
+ extraFormat = {},
+ scale = AMOUNT_DECIMAL_SCALE
+) {
const format = { ...extraFormat }
fields.forEach(field => {
- format[field] = { decimalPlaces: AMOUNT_DECIMAL_SCALE }
+ format[field] = { decimalPlaces: scale }
})
return format
}
--
Gitblit v1.9.3