js获取小数点后两位

<script type="text/javascript">
//字符串处理
function f1(obj){
var regDecimal = /^\d+(.\d+)?$/;
        if (regDecimal.test(obj)) {
            if (obj.toString().indexOf(".") > 0) {
                obj = obj.toString() + "00";
                obj = obj.substring(0, obj.indexOf(".") + 3);
            } else {
                obj = obj + ".00";
            }
        }
return obj;
}

//js内置四舍五入
function f3(num){
return num.toFixed(2);
}
</script>

posted @ 2016-05-31 11:22  妍柒柒  阅读(1844)  评论(0编辑  收藏  举报