0

I have got this script which multiplies value inputted into input field by dropdown's value assigned through span data-val.

How can I make the script show result rounded up to 3 decimals?

$(document).ready(function () {
    function showTab(name) {
        $('div.fruit').hide();
        var $div = $('#' + name).show();
        var number = parseInt($('.number').val(), 0);
        $('span', $div).each(function () {
            $(this).text($(this).data('val') * number);
        });
    }

    $('#update').click(function() { 
        showTab($('#dropdown').val());
    });

    showTab($('#dropdown').val());
});
user2357112
  • 260,549
  • 28
  • 431
  • 505
Andy Andy
  • 279
  • 4
  • 7
  • 17
  • check: http://stackoverflow.com/questions/6134039/format-number-to-always-show-2-decimal-places – rags Nov 14 '13 at 08:42

1 Answers1

1

try

$(this).text(($(this).data('val') * number).toFixed(3));
mplungjan
  • 169,008
  • 28
  • 173
  • 236