Last active
November 20, 2022 15:48
-
-
Save kafeltz/1b99cbaa9dc2142e04ca to your computer and use it in GitHub Desktop.
Solução brutalmente simples pra formatar moeda brasileira (BRL) de float pra string. Sem framework ou lib. Altere conforme a necessidade.
This file contains 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
// http://blog.tompawlak.org/number-currency-formatting-javascript | |
// http://www.javascripter.net/faq/tofixed.htm | |
function _format(num) | |
{ | |
return num.toFixed(2).replace(".", ",").replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://jsfiddle.net/shalanga/vL9ktu9m/