题解 | #乘法#

乘法

http://www.nowcoder.com/practice/6429776e4630435cbc3eeb36bdf41f83

思路:先换成整数,再乘,再除

function multiply(a, b) {
    let s1=a.toString(), s2=b.toString(), m=0;
    if(s1.includes('.')){
        m+=s1.split('.')[1].length
    }
    if(s2.includes('.')){
        m+=s2.split('.')[1].length
    }
    return s1.replace('.','')*s2.replace('.','')/Math.pow(10,m)
}
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务