数字的千位转换

//三位加,
toThousands(num){
    return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');
}
//超过十万转换成万为单位并取整,其他情况不变
numberConvert(num){
    if (num<100000){
        return this.toThousands(num);
    }
    else{
        let afternum=(this.toThousands(parseInt(Math.round((num /10000) * 100) / 100)));
        let numstr=afternum+'万';
        return numstr;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_41606276/article/details/99634218