保留两位小数,不四舍五入

2018-07-16  本文已影响0人  my沙漠玫瑰

//验证出金金额(只能输入两位小数,不四舍五入)

html代码:

<input type="text" placeholder="请输入金额" onchange=" yzcj_amount (this)"/>

js代码:

function yzcj_amount(a){

    var yzcj_amount=Math.floor(parseFloat($(a).val())*100)/100;

    var xsd=yzcj_amount.toString().split(".");

    if(xsd.length==1){

        yzcj_amount=yzcj_amount.toString()+".00";

}

    if(xsd.length>1){

        if(xsd[1].length<2){

            yzcj_amount=yzcj_amount.toString()+"0";

        }

    }

    $(a).val(parseFloat(yzcj_amount))

}

上一篇 下一篇

猜你喜欢

热点阅读