From f1b0fc588a747b9b8bb4ad125535630c34f94e82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=8E=E6=B0=B8=E9=A1=BA?= <971387674@qq.com> Date: Wed, 6 Dec 2023 14:49:34 +0800 Subject: [PATCH] 1release/2.9.9.2312.01 --- pc4mobx/hrmSalary/util/index.js | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/pc4mobx/hrmSalary/util/index.js b/pc4mobx/hrmSalary/util/index.js index 65a739ff..e5b3c1aa 100644 --- a/pc4mobx/hrmSalary/util/index.js +++ b/pc4mobx/hrmSalary/util/index.js @@ -117,17 +117,10 @@ export const padding0 = (num, length) => { } return "0." + num; }; -export const toDecimal_n = (x, num) => { - if (isNaN(parseFloat(x))) return false; - let f = Math.round(x * Math.pow(10, num)) / Math.pow(10, num); - let s = f.toString(); - let rs = s.indexOf("."); - if (rs < 0) { - rs = s.length; - s += "."; - } - while (s.length <= rs + num) { - s += "0"; - } - return s; +export const toDecimal_n = (num, decimalPlaces) => { + if (num === null || !isFinite(num)) return null + if (decimalPlaces < 0) return null; + const multiplier = Math.pow(10, decimalPlaces); + const roundedNum = Math.round(num * multiplier) / multiplier; + return roundedNum.toFixed(decimalPlaces); };