You must Sign In to post a response.
  • Category: JQuery

    Jquery Sum Does not give Exact Output ()

    hi developers
    Am using the jquery for Calculate sum.

    Total , Tax , GrandTotal
    GrandTotal=Total + Total*Tax/100;

    if 1.
    Total = 1000.45
    Tax =124.25
    GrandTotal Will be Value =2242.95 but it gives like Value =2243.51

    2.
    Total = 200.50
    Tax =10.25
    GrandTotal Will be Value =221.00 but it gives like Value =221.05

    i can't able to Resolve this Critical problem. this is very Important for my project.
    this will be go to Quotation.

    My Code is
    JQUERY

    <script src="Tracking/js/jquery.js" type="text/javascript"></script>

    <script>
    function txtpercentage() {
    var ch1 = $("#txtQUOTETotal").val();
    var tax = $("#txtQUOTETax").val();

    var grandTotal;
    var ch3 = ch1 * tax / 100;
    grandTotal = parseFloat(ch1) + parseFloat(ch3);

    $("#txtQUOTEGrandTotal").html(grandTotal.toFixed(2));

    }
    </script>

    Client side Aspx Code


    <table>

    <tr>
    <td>
    <asp:Label ID="Label32" runat="server" Text="Total"></asp:Label>
    <span style="float:right"><span style="color:red;">*</span> : </span></td>
    <td>
    <asp:TextBox ID="txtQUOTETotal" runat="server" AutoComplete="off" Width="250px"
    onkeyup="txtpercentage()"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator24" runat="server"
    ControlToValidate="txtQUOTETotal" ErrorMessage="*" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label33" runat="server" Text="Tax"></asp:Label>
    <span style="float:right"><span style="color:red;">*</span> : </span></td>
    <td>
    <asp:TextBox ID="txtQUOTETax" runat="server" AutoComplete="off" Width="250px" onkeyup="txtpercentage()"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator25" runat="server"
    ControlToValidate="txtQUOTETax" ErrorMessage="*" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label36" runat="server" Text="Grand Total"></asp:Label>
    <span style="float:right"><span style="color:red;">*</span> : </span></td>
    <td>
    <asp:Label ID="txtQUOTEGrandTotal" runat="server" class="add"
    AutoComplete="off" Width="250px"></asp:Label>

    </td>
    </tr>
    </table>

    so anyone know how to fix this problem.
    Please help to me.

    thanks with
    Paul.S
  • #767733
    just add three online link
    <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.10.2.js" /></script>
    <script src="http://code.jquery.com/ui/1.10.4/jquerZy-ui.js" /></script>

    full code:--

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title></title>

    <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet" />
    <script src="http://code.jquery.com/jquery-1.10.2.js" /></script>
    <script src="http://code.jquery.com/ui/1.10.4/jquerZy-ui.js" /></script>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>

    <script>
    function txtpercentage() {
    var ch1 = $("#txtQUOTETotal").val();
    var tax = $("#txtQUOTETax").val();

    var grandTotal;
    var ch3 = ch1 * tax / 100;
    grandTotal = parseFloat(ch1) + parseFloat(ch3);

    $("#txtQUOTEGrandTotal").html(grandTotal.toFixed(2));

    }
    </script>
    Client side Aspx Code
    <table>
    <tr>
    <td>
    <asp:Label ID="Label32" runat="server" Text="Total"></asp:Label>
    <span style="float: right"><span style="color: red;">*</span> : </span>
    </td>
    <td>
    <asp:TextBox ID="txtQUOTETotal" runat="server" AutoComplete="off" Width="250px" onkeyup="txtpercentage()"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator24" runat="server" ControlToValidate="txtQUOTETotal"
    ErrorMessage="*" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label33" runat="server" Text="Tax"></asp:Label>
    <span style="float: right"><span style="color: red;">*</span> : </span>
    </td>
    <td>
    <asp:TextBox ID="txtQUOTETax" runat="server" AutoComplete="off" Width="250px" onkeyup="txtpercentage()"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator25" runat="server" ControlToValidate="txtQUOTETax"
    ErrorMessage="*" ForeColor="Red" SetFocusOnError="True"></asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td>
    <asp:Label ID="Label36" runat="server" Text="Grand Total"></asp:Label>
    <span style="float: right"><span style="color: red;">*</span> : </span>
    </td>
    <td>
    <asp:Label ID="txtQUOTEGrandTotal" runat="server" class="add" AutoComplete="off"
    Width="250px"></asp:Label>
    </td>
    </tr>
    </table>
    </div>
    </form>
    </body>
    </html>


  • Sign In to post your comments