Created
October 9, 2018 18:55
-
-
Save rogerramosme/2b142c51a478c82b6a01078e68ee7222 to your computer and use it in GitHub Desktop.
Format currency BR using toLocalString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const formatCurrencyBRL = (price, showLeadingCurrency = true) => { | |
price = Math.round(price * 100) / 100; | |
const options = { | |
style: showLeadingCurrency ? "currency" : "decimal", | |
currency: "BRL", | |
minimumFractionDigits: 2 | |
}; | |
return price.toLocaleString( | |
"pt-Br", | |
options | |
); | |
}; | |
console.log(formatCurrencyBRL(1500)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment