br-currency-formatter
v1.0.3
Published
A simple package to convert any number in a formated currency BR number
Downloads
2
Maintainers
Readme
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!