0

试图让变量“totalreq”显示为一个整数。我已经尝试了一些数学地板数学回合等示例。此时,如果我什至删除我添加的 toFixed(2),它就会中断。有人对我有什么想法吗?

    $(document).ready(function()
{
$('#calc').keyup(function()
{   
//Calculate part A by adding
    var totala = parseInt($('#mortgages').val()) + parseInt($('#loans').val())          + parseInt($('#expenses').val());
    $('#resulta').text("$" + totala);
//Calculate the complex b1 
    var percentageincome = (70 / 100);
    var tvf = $('#timevaluefactor').val();
    var totalreq = parseInt($('#bgross').val()) * (percentageincome) * (tvf);
    $('#line4result').text("$" + (totalreq.toFixed(2)));
//add b1 to b2)
    var totalb = parseInt($('#efund').val()) + parseInt($('#childcare').val()) + parseInt($('#education').val()) + (totalreq);
    $('#resultb').text("$" + totalb);
//calculate c by adding
    var totalc = parseInt($('#cash').val()) + parseInt($('#stock').val()) + parseInt($('#estate').val()) + parseInt($('#business').val()) + parseInt($('#insloans').val()) + parseInt($('#totalbenefit').val()) + parseInt($('#otherdb').val());
    $('#resultc').text("$" + totalc);
//a + b - c = result
    var finalresult = parseInt(totala) + parseInt(totalb) - parseInt(totalc);
    $('#result').text("$" + finalresult);

});

});

4

0 回答 0