Javascript 如何在使用复选框计算时保持.00

Javascript 如何在使用复选框计算时保持.00,javascript,jquery,Javascript,Jquery,如果我启用/禁用复选框按钮,则添加的.00将从金额中删除 我如何将.00添加到金额中 下面是我的代码: function checks() { document.getElementById('other_donation_check').checked = false; } function add(total, this_chk_bx) { var thetotal = form2.thetotal.value; if (this_chk_bx.checked =

如果我启用/禁用复选框按钮,则添加的.00将从金额中删除

我如何将.00添加到金额中

下面是我的代码:

function checks() {
    document.getElementById('other_donation_check').checked = false;
}

function add(total, this_chk_bx) {
    var thetotal = form2.thetotal.value;

    if (this_chk_bx.checked == true) {
        //add if its checked
        var count=0;
        form2.thetotal.value = Number(thetotal) + Number(total);
        count++;
    } else {
        //subtract if its unchecked
        form2.thetotal.value = thetotal - total;
    }
}
我创造了一个


如何解决此问题?

在下面找到一个片段,使用
toFixed()
演示您试图实现的目标;你可以用你的实际逻辑来扩展它

(函数添加(){
document.getElementById(“其他捐赠检查”).addEventListener(“单击”,函数)(){
var this_chk_bx=document.getElementById('other_check')。选中;
风险值金额=2,
金额=250;
如果(此值为真){
console.log('is checked');
var thetotal=eval(金额2+金额1);
console.log(固定的总时间(2));
}否则{
console.log('未选中');
var thetotal=eval(金额2+金额1);
console.log(总数);
}
});
}());
选中/取消选中下面的复选框以查看正在运行的代码


Number.toFixed(2)to fixed将其转换为一个带n位小数的字符串。我尝试了.toFixed(2)方法,但没有找到。请检查我的代码“var thetotal=form2.Number(thetotal).value.toFixed(2);”是否可能重复抱歉,我这样做了,但没有成功。