Lipto Nice Tea Lipto Nice Tea -3 years ago 152
Javascript Question

How can I make the jQuery Mask Plugin display prices with a period instead of a comma?

I'm using the jQuery Mask Plugin library for inputs containing prices. This library is adding a comma in the input price format, but I need a dot for the price. I can't find where this functionality is in the library.

Example: If you write "1990" it's masking as "19,90" (with a comma).
But I want "1990" -> "19.90" (with a dot).

The library I am using is here: https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.js

Answer Source

I think you want to do something like this. Check out the recursive digits section in the docs.

You just need to replace the , with a .

$('.currency').mask("#,##0.00", {
  reverse: true
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.13.4/jquery.mask.min.js"></script>
<input class="currency" type="text" value="1990">

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download