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());
});
Andy Andy
  • 279
  • 3
  • 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
  • 155,085
  • 27
  • 166
  • 222