How to delete in autoNumeric in input the fractional part of the extra zeros The mDec parameter adds the fractional part, but when you remove the focus from the element, if the fractional part is missing, then add zeros equal to the specified parameter

You need to convert by example

1.22500 => 1.255

1.00 => 1

1.90 => 1.9

I would like this to be some kind of parameter, rather than manually writing

Plugin version 1.9.46

  • Try the method myval = myval.toString () should leave - user2455111
  • I would like that it was just a parameter - ruslik
  • parseFloat (variable); - L. Vadim
  • Conversions in input are needed, when focus is reset - ruslik
  • parseFloat (variable) when the value is converted, it is put again in the input, but the mDec parameter is already there, therefore parseFloat (1.23000) is converted again to 1.23000 - ruslik

2 answers 2

Make the onblur function and parseFloat off with parseFloat :

 (function() { document.querySelector('input').onblur = function() { if(/^[-0-9.,]+$/.exec(this.value)){ this.value = parseFloat(this.value.replace(/\,/g, '.')); }; }; })(); 
 <input type="text" placeholder="Введите число"> 

    There is such a parameter aPad: false