浏览代码

update Web/src/utils/commonFunction.ts.
添加千分符函数,默认保留两位小数

Signed-off-by: npc6 <jjwsoft@qq.com>

npc6 2 年之前
父节点
当前提交
aab08a7a60
共有 1 个文件被更改,包括 8 次插入0 次删除
  1. 8 0
      Web/src/utils/commonFunction.ts

+ 8 - 0
Web/src/utils/commonFunction.ts

@@ -38,6 +38,13 @@ export default function () {
 	const scale2Format = (value: string = '0') => {
 		return Number.parseFloat(value).toFixed(2);
 	};
+    // 千分符,默认保留两位小数
+	const groupSeparator = (value: number, minimumFractionDigits: number = 2) => {
+		return value.toLocaleString('en-US', {
+			minimumFractionDigits: minimumFractionDigits,
+			maximumFractionDigits: 2,
+		});
+	};
 	// 点击复制文本
 	const copyText = (text: string) => {
 		return new Promise((resolve, reject) => {
@@ -75,6 +82,7 @@ export default function () {
 		dateFormatHMS,
 		scaleFormat,
 		scale2Format,
+        groupSeparator,
 		copyText,
 		removeHtmlSub,
 		removeHtml,