Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solução brutalmente simples pra formatar moeda brasileira (BRL) de float pra string. Sem framework ou lib. Altere conforme a necessidade.
// 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.");
}
@kafeltz

This comment has been minimized.

Copy link
Owner Author

commented Aug 12, 2015

- 0.1     0,10
- 0.11    0,11
- 0.111   0,11
- 0.99    0,99
- 1       1,00
- 10      10,00
- 100     100,00
- 1000    1.000,00
- 10000   10.000,00
- 100000  100.000,00
- 1000000 1.000.000,00
- 99.99   99,99
- 99.999  100,00
- 99.01   99,01
- 99.09   99,09
- 99.199  99,20

https://jsfiddle.net/shalanga/vL9ktu9m/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.