Imask.js set currency symbol to the and of number by appending changeable double zero to the end of price

Viewed 2499

How to do input masking something like this by appending doube zero by default to the end of price using js library imask.js or with plain javascript : 3.380.321,00 $

var currencyMask = IMask(
  document.getElementById('price'),
  {
    mask: '$num',
    blocks: {
      num: {
        mask: Number,
        thousandsSeparator: '.'
      }
    }
  });

var currencyMask = IMask(
  document.getElementById('price2'),
  {
    mask: 'num$',
    blocks: {
      num: {
        mask: Number,
        thousandsSeparator: '.'
      }
    }
  });
<script src="https://unpkg.com/imask"></script>
<input type="text" id="price" value="2700300.21">
<hr>
<p>Needed masking: 3.380.321,00 $</p>
<input type="text" id="price2">

1 Answers

Try this

var currencyMask = IMask(
  document.getElementById('price'),
  {
    mask: [
        { mask: '' },
        {
            mask: 'num $',
            lazy: false,
            blocks: {
                num: {
                    mask: Number,
                    scale: 2,
                    thousandsSeparator: '.',
                    padFractionalZeros: true,
                    radix: ',',
                    mapToRadix: ['.'],
                }
            }
        }
    ]
  });
<script src="https://unpkg.com/imask"></script>
<input type="text" id="price" value="3380321.00">

Related