Click here to Skip to main content
15,886,772 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I m trying to calculate total amount and total vat percentage in may code, but its gives me nun result.

here is my jQuery code.
JavaScript
function getPackagevalues()
    {
        debugger;
        var total=0;
        var vattot=0;
        alert('inclide getPackagevalues');
        $("#mytab1").find("tbody tr").each(function()
        {

            if($(this).find("td:eq(8)").text()!=null && $(this).find("td:eq(8)").text()!="")
            {
                var val=parseInt($(this).find("td:eq(8)").text(),10);
                total+=val;
            }
            if($(this).find("td:eq(7)").text()!=null && $(this).find("td:eq(7)").text()!="")
            {
                var val2=parseInt($(this).find("td:eq(7)").text(),10);
                vattot+=val2;
            }
        });

        document.getElementById("netamt").value=total.toFixed(2);
        document.getElementById("vattotal").value=vattot.toFixed(2);
    }


In this result it gives is nan. any one please help me to solve this.
thanks in advance
Posted
Updated 1-Aug-15 0:37am
v3
Comments
Richard MacCutchan 31-Jul-15 3:58am    
Where does the error occur, and what are the inputs that cause it? Also, you should not use float values for financial calculations, as they lose precision.
Afzaal Ahmad Zeeshan 2-Aug-15 10:35am    
Did you mean NaN? Non a number, instead of NuN.

1 solution

use 'parseFloat' Function on javascript ;

JavaScript
var n = parseFloat("60 42 abc")


result will be like this :
60
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900