br-currency-formatter

1.0.3 • Public • Published

br-currency-formatter

Simple package that converts any passed number to currency value. Below:

Usage

  npm install br-currency-formatter

or

  yarn add br-currency-formatter

to use inside project, use:

import anyNumberToBrCurrency from 'br-currency-formatter';

Returns

anyNumberToBrCurrency("12345")
//12.345,00
anyNumberToBrCurrency("12345,00")
//12.345,00
anyNumberToBrCurrency("1,456.00")
//1.456,00
anyNumberToBrCurrency("1.456,00")
//1.456,00
anyNumberToBrCurrency("1,456,00")
//1.456,00
anyNumberToBrCurrency("1.456.00")
//1.456,00

Works with invalid numbers too

anyNumberToBrCurrency("1..,456.,.00")
//1.456,00
anyNumberToBrCurrency("1..,,,,.,.456.,.00")
//1.456,00

Sign

To put the sign "R$" in all formatations, pass true on second function call parameter, like this:

  anyNumberToBrCurrency("45655,43", true)
  //R$ 45.655,43

More decimal places

To show more decimal places, use this:

  anyNumberToBrCurrency("45655,435", true, 3)
  //R$ 45.655,435

Enjoy it!

Package Sidebar

Install

npm i br-currency-formatter

Weekly Downloads

4

Version

1.0.3

License

ISC

Unpacked Size

3.61 kB

Total Files

4

Last publish

Collaborators

  • willdev99