Skip to content

Instantly share code, notes, and snippets.

@brandonaaskov
Created January 27, 2019 17:32
Show Gist options
  • Save brandonaaskov/1a8bf6cd36d5b066a69d966117488470 to your computer and use it in GitHub Desktop.
Save brandonaaskov/1a8bf6cd36d5b066a69d966117488470 to your computer and use it in GitHub Desktop.
Uses vanilla JS to format numbers for different locales.
const formattedNumber = (value, decimals = 2, locale = 'pt-BR') => {
const oNumber = new Intl.NumberFormat(locale, {
maximumFractionDigits: decimals,
minimumFractionDigits: decimals
});
return oNumber.format(value);
};
formattedNumber(889999) // 889.999,00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment