huangbin 4 years ago
parent
commit
af365bca36
2 changed files with 7 additions and 5 deletions
  1. 1 1
      src/common/setup/table/list.ts
  2. 6 4
      src/utils/number/index.ts

+ 1 - 1
src/common/setup/table/list.ts

@@ -28,7 +28,7 @@ export function queryTableList<T>(ishandleFloatErr = false) {
                 if (ishandleFloatErr) {  // 折中方案:处理浮点失真,如果页面卡顿,则需要服务处理
                     result?.forEach((e: T, i: number) => {
                         for (const item in e) {
-                            e[item] = getDecimalsNum(e[item])
+                            e[item] = getDecimalsNum(e[item], 6, (e as any).decimalplace)
                         }
                     });
                 }

+ 6 - 4
src/utils/number/index.ts

@@ -9,10 +9,12 @@ export function getDecimalsNum(val: any, decimal = 2, maxCount = 6) {
     let result = val
     if (typeof val === 'number') {
         const str = val.toString();
-        const num = str.indexOf('.') + 1;
-        const count = str.length - num;
-        if (count > maxCount) {
-            result = val.toFixed(decimal)
+        if (str.includes('.')) {
+            const num = str.indexOf('.') + 1;
+            const count = str.length - num;
+            if (count > maxCount) {
+                result = val.toFixed(decimal)
+            }
         }
     }
     return result