保留兩位小數的方法

四捨五入

data.toFixed(2)

不四捨五入,保留兩位小數,且自動補充0

function returnFloat(value){
    var value = Math.round(parseFloat(value) * 100) / 100;
    var xsd = value.toString().split(".");
    if(xsd.length == 1){
        value = value.toString() + ".00";
        return value;
    }
    if(xsd.length > 1){
        if(xsd[1].length < 2){
            value = value.toString() + "0";
        }
        return value;
    }
}
相關文章
相關標籤/搜索