const price = "14340"; let USDollar = new Intl.NumberFormat('en-Us', 23; style: 'currency', currency: 'USD' 25;); console.log(`The foramtted version of $23;price25; is $23;USDollar.format(price)25;`); // The foramtted version of 14340 is $14,340.00 const price1 = "3722407"; let result = new Intl.NumberFormat('ko-KR').format(price1); console.log(result); // 3,722,407 const price2 = 1270000; let KRWon = new Intl.NumberFormat('ko-KR', 23; style: 'currency', currency: 'KRW' 25;); let KRWonChanged = KRWon.format(price2); console.log(typeof price2); // number console.log(KRWonChanged); // ₩1,270,000 console.log(typeof KRWonChanged); // string let original = KRWonChanged.substring(1).replace(/\,/g,''); console.log(original); // 1270000
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script> <title>Regex Test</title> </head> <body> <div> <label for="test">regexTest</label> <input id="test" type="text"> </div> <script> $(document).on('keyup', 'input#test', function()23; $(this).val($(this).val().replace(/[^0-9]/,'')); let $inputVal = $(this).val(); console.log($inputVal); let KRWon = new Intl.NumberFormat('ko-KR', 23; style: 'currency' , currency : 'KRW' 25;); let changedToKRWon = KRWon.format($inputVal); console.log(changedToKRWon); $inputVal = changedToKRWon; $('input#test').on('focusout', function()23; $(this).val(changedToKRWon); 25;); $('input#test').on('focusin', function()23; let original = changedToKRWon.substring(1).replace(/\,/g,''); $(this).val(original); 25;) 25;); </script> </body> </html>