0

Here are my code and its showing 00.000.000.00. I have changed this code another way then it's showing only the first digit of the result.

$(document).on('change', '.prc', function() {
  var tSum = 0;
  $('.prc').each(function() {
    tSum += parseFloat($(this).val());
  });
  $('.totalprc').val(tSum);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input class="prc" value="0.00" />
<input class="prc" value="0.00" />
<input class="prc" value="0.00" />

<input class="totalprc" />
adiga
  • 34,372
  • 9
  • 61
  • 83
Imran
  • 1
  • 2
  • 1
    `$(this).val()` is a string. Use `parseFloat($(this).val())` – adiga Feb 19 '20 at 14:25
  • I have tried this but it's don't showing the correct answer. – Imran Feb 19 '20 at 14:29
  • Please create a [mcve] by creating [a runnable stack snippet?](https://meta.stackoverflow.com/questions/358992) – adiga Feb 19 '20 at 14:30
  • I don't know how to do it. I am new! btw thanks! I will try from another site. – Imran Feb 19 '20 at 14:33
  • Click on the second link in the previous comment. (I have added a snippet. If you add `parseFloat`, it seems to work. Please [edit] it to reproduce the issue) – adiga Feb 19 '20 at 14:37
  • I have checked that. Please check it. **parseFloat, parseInt** don't work. I want to show **10 + 10 = 20** but it showing **010100.00**. I didn't get what is the problem. – Imran Feb 19 '20 at 14:57
  • Added `parseFloat` logic to the question and it is working – adiga Feb 20 '20 at 06:54

0 Answers0