jquery format number to currency code example

Example 1: javascript format price

// Javascript has a number formatter (part of the Internationalization API).

const number = 123456.789;

// another example 
console.log(new Intl.NumberFormat('ja-JP',  {
  style: 'currency',
  currency: 'BWP',
}).format(number));

// MORE INFO ->  https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

Example 2: display amount with currency for jquery

$(document).ready(function(){
  $('#test').click(function() {
    TESTCURRENCY = $('#value').val().toString().match(/(?=[\s\d])(?:\s\.|\d+(?:[.]\d+)*)/gmi);
    if (TESTCURRENCY.length <= 1) {
      $('#valueshow').val(
        parseFloat(TESTCURRENCY.toString().match(/^\d+(?:\.\d{0,2})?/))
      );
    } else {
      $('#valueshow').val('Invalid a value!');
    }
  });
});