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); };