题解 | #乘法#
乘法
https://www.nowcoder.com/practice/6429776e4630435cbc3eeb36bdf41f83
function multiply(...args) {
let len = Math.max(args[0].toString().includes(".") ? args[0].toString().split(".")[1].length : 0, args[1].toString().includes(".") ? args[1].toString().split(".")[1].length : 0)
let divisor = Math.pow(10,len) * Math.pow(10,len)
let count = args.reduce((count,num)=> count *= num*Math.pow(10,len) ,1)
return count /= divisor
}
将小数变为整数,自然不用考虑精度问题
查看1道真题和解析