1release/2.9.9.2312.01

This commit is contained in:
黎永顺 2023-12-06 14:49:34 +08:00
parent bc78a26578
commit f1b0fc588a
1 changed files with 6 additions and 13 deletions

View File

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