Created
July 2, 2018 21:19
-
-
Save marco-souza/b1bc2314265f25c60884deb8fea00e7a to your computer and use it in GitHub Desktop.
Format a simple number to Reais
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
| function formatMoney(n) { | |
| return "R$ " + n.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+\,)/g, "$1."); | |
| } | |
| // or (ES6) | |
| const formatMoney = n => `R$ ${n.toFixed(2).replace('.', ',').replace(/(\d)(?=(\d{3})+\,)/g, "$1.")}` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment