Skip to content

Instantly share code, notes, and snippets.

@rogerramosme
Created October 9, 2018 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogerramosme/2b142c51a478c82b6a01078e68ee7222 to your computer and use it in GitHub Desktop.
Save rogerramosme/2b142c51a478c82b6a01078e68ee7222 to your computer and use it in GitHub Desktop.
Format currency BR using toLocalString
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