ishaq
ishaq

Reputation: 177

Fix Number after Decimal to One Digit

I am using the below code to have an increment and decrement functionality. But somehow it is not fixed to one digit after decimal places it works fine on Firefox but chrome sometimes adds trailing zeros or other random numbers.

How to fix it.

  <script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('.qty-inc').click(function () {
            jQuery('.qty-default').val(Number(jQuery('.qty-default').val())+0.1);
        });

        jQuery('.qty-dec').click(function () {
                var value = Number(jQuery('.qty-default').val())-0.1;
                if(value > 0){
                    jQuery('.qty-default').val(value);
                }

        });
    });
    
</script>

enter image description here

Upvotes: 0

Views: 351

Answers (1)

Ruchi Sharma
Ruchi Sharma

Reputation: 140

var finalvalue = value.toFixed(1);

Upvotes: 1

Related Questions