题解 | #乘法#

乘法

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
}

将小数变为整数,自然不用考虑精度问题

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务