Home > database >  Fix Number after Decimal to One Digit
Fix Number after Decimal to One Digit

Time:04-09

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

CodePudding user response:

var finalvalue = value.toFixed(1);

  • Related