format-money-js
TypeScript icon, indicating that this package has built-in type declarations

1.6.3 • Public • Published

format-money-js

Build Status version download per month

Zero dependency tiny JavaScript library (841 bytes) by CurrencyRate.today, providing simple way and advanced number, money and currency formatting and removes all formatting/cruft and returns the raw float value. Size of library: 841 bytes in zip and 1.2 kByte in min formats.

Functions

from: money and currency formatting;

un: removes all formatting/cruft and returns the raw float value.

Examples

const { FormatMoney } = require('format-money-js');

const fm = new FormatMoney({
  decimals: 2
});

console.log(fm.from(12345.67, { symbol: '$' })); // return string: $12,345.67
console.log(fm.un('€12,345;67')); // return number: 12345.67
const { FormatMoney } = require('format-money-js');

const fm = new FormatMoney({
  decimals: 2
});

console.log(fm.from(
  12345.67, 
  { symbol: '$' },
  true // Parse, return object
  )
);
/* return object: 
{
  source: 12345.67,
  negative: false,
  fullAmount: '12,345.67',
  amount: '12,345',
  decimals: '.67',
  symbol: '$'
}*/

Options

You can added options in construct of class and in method. But method will be primary.

Example:

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

console.log(fm.from(12345.67, { symbol: '€' })); // €12,345.67
console.log(fm.un('€12.345,67', { decimalPoint: ',' })); // 12345.67
Name Default Type Example
grouping true Boolean 1,000 (true) vs 1000 (false)
separator , String 1,000
decimalPoint . String 1,234.56
decimals 0 Number 1,234 (0 - without decimals)
symbol None String $1,234.56 (if append false)
append false String 1,234.56$ (if append true)
leadZeros true Boolean true - 1.10, false - 1.1 (leading zeros)

Source

https://currencyrate.today/

https://fx-w.io/

https://moneyconvert.net/

https://cr.today/

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.6.3
    2,021
    • latest

Version History

Package Sidebar

Install

npm i format-money-js

Weekly Downloads

2,851

Version

1.6.3

License

BSD-2-Clause

Unpacked Size

25.8 kB

Total Files

17

Last publish

Collaborators

  • yydarwin