I have the following script for calculating the average of the rows of an HTML table:
$(document).ready(function() {
  $('tr').each(function() {
    var count = 0;
    var totmarks = 0;
    $(this).find('.subjects').each(function() {
      var marks = $(this).text();
      if (marks.lenght !== 0) {
        totmarks += parseFloat(marks);
        count += 1;
      }
    });
    $(this).find('#TotMarks').html(totmarks / count);
  });
});<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table border="1" style="text-align:center;">
  <thead>
    <tr>
      <th>Student Name</th>
      <th>Math</th>
      <th>Spanish</th>
      <th>Science</th>
      <th>Average</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Pedro</td>
      <td class="subjects">4.0</td>
      <td class="subjects">5.0</td>
      <td class="subjects">6.0</td>
      <td id="TotMarks"></td>
    </tr>
  </tbody>
</table>Then the average column will display the integer 5 instead of 5.0, is there a solution for this?
 
     
     
     
    