Created
January 27, 2019 17:32
-
-
Save brandonaaskov/1a8bf6cd36d5b066a69d966117488470 to your computer and use it in GitHub Desktop.
Uses vanilla JS to format numbers for different locales.
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 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