Ultra Small Currency Fomatting Library – format-money-js

Category: Javascript | February 5, 2023
Author:dejurin
Views Total:212 views
Official Page:Go to website
Last Update:February 5, 2023
License:BSD-2-Clause

Preview:

Ultra Small Currency Fomatting Library – format-money-js

Description:

format-money-js is an ultra-light (~600 bytes) and standalone currency formatting JavaScript library for the web.

Comes with a number of formatting options to output currency values in a customized way.

How to use it:

1. Download and import the format-money-js library into the document.

<script src="dist/format-money.js"></script>

2. Format a currency value you provide.

const fm = new FormatMoney();
fm.from(12345.67, { 
  symbol: '$' 
}) // => $12,345,67

3. Customize the number of decimal places. Default 0.

const fm = new FormatMoney({ 
      symbol: '$' ,
      decimals: 2
});

4. Customize the string that separates the thousands of the currency value.

const fm = new FormatMoney({ 
      symbol: '$' ,
      separator: ','
});

5. Customize the string that separates the integer and the fraction parts of the currency value.

const fm = new FormatMoney({ 
      symbol: '$' ,
      decimalPoint: '.'
});

6. Enable/disable the thousands delimiter. Default: true.

const fm = new FormatMoney({ 
      symbol: '$' ,
      grouping: false // => 1234
});

7. Append the currency symbol to the end of the formatted value.

const fm = new FormatMoney({ 
      symbol: '$' ,
      append: true // => 12,345,67$
});

8. Determine whether to enable lead zeros.

const fm = new FormatMoney({ 
      leadZeros: true // => true - 1.10, false - 1.1
});

Changelog:

v1.6.2 (02/05/2023)

  • Added leadZeros option

v1.5.5 (09/30/2022)

  • Updated JS

v1.5.3 (09/27/2022)

  • Updated JS

v1.5.0 (09/26/2022)

  • Updated JS

v1.4.3 (01/27/2021)

  • Updated JS

v1.3.3 (11/01/2020)

  • Updated JS

You Might Be Interested In:


Leave a Reply