You are viewing limited content. For full access, please sign in.

Question

Question

How to limit digits after the decimal when subtracting two fields?

asked on January 7, 2016

Hi all, 

 

I am subtracting two field, my code looks like this so far:

$(document).ready(function () { 
  $('#q42 input, #q43 input').change(function () {
    $('#q29 input').val($('#q42 input').val() - $('#q43 input').val());
  });
});

which is working fine, except that there are too many numbers after the decimal. How would I go about limiting this number to 5 digits? Here is a screenshot:

 

 

Thanks!

0 0

Answer

SELECTED ANSWER
replied on January 7, 2016

Try changing line 3 in the above Javascript to

$('#q29 input').val(($('#q42 input').val() - $('#q43 input').val()).toFixed(5));

2 0
replied on January 8, 2016

Perfect, thank you!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.