• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

140
Views
I want to fixed the decimal places of the textbox value

The function below also calculates the sum on run time. The txtRate is the textbox to be processed for the decimal fix.

$(function() {
  $("[id*=txtRate]").val("0");
});
$("body").on("change", "[id*=txtRate]", function() {
  var rate = parseFloat($.trim($(this).val()));
  if (isNaN(rate)) {
    rate = 0;
  }
  //Update the Rate TextBox.
  $(this).val(rate);
  //Calculate and update Row Total.
  var row = $(this).closest("tr");
  $("[id*=lblTotal]", row).html(parseFloat($(".quantity", row).html()) * parseFloat($(this).val()));

  //Calculate and update Grand Total.
  var grandTotal = 0;
  $("[id*=lblTotal]").each(function() {
    grandTotal = grandTotal + parseFloat($(this).html());
  });
  $("[id*=lblGrandTotal]").html(grandTotal.toString());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error