美文网首页
保留两位小数,不四舍五入

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

作者: my沙漠玫瑰 | 来源:发表于2018-07-16 13:30 被阅读0次

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

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))

}

相关文章

网友评论

      本文标题:保留两位小数,不四舍五入

      本文链接:https://www.haomeiwen.com/subject/vzjnfftx.html