function getPercent1(num, total) {
num = parseFloat(num);
total = parseFloat(total);
if (isNaN(num) || isNaN(total)) {
return "-";
}
// toFixed 小数点向上取整
return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.00).toFixed(0) + "%";
}
let res = getPercent1(45, 65)
console.log(res) // 69%
let res11 = getPercent1(20, 65)
console.log(res11) // 31%
js生成一定范围内的随机整数
Math.floor(Math.random()*(m-n+1)+n)
Math.floor(Math.random() * (50 - 1 + 1) + 1);