JavaScript number format currency | Example code

  • by

Use NumberFormat to get the number format currency in JavaScript. This is part of the Internationalization API. This constructor creates Intl.NumberFormat objects that enable language-sensitive number formatting.

Example get number format currency in JavaScript

simple example code.

<!DOCTYPE html>
<html>
<body>

  <script>

   var formatter = new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: 'USD',});

   console.log(formatter.format(2500)); 
   console.log(formatter.format(1000000)); 
 </script>

</body>
</html>

Output:

JavaScript number format currency

Do comment if you have any doubts or suggestions on this JS format currency topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.