Created
October 25, 2012 06:12
-
-
Save oraculum/3950800 to your computer and use it in GitHub Desktop.
Formatando valores monetários em javascript
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
$("#preco_total").text("R$ " + numberFormat(total.toFixed(2))) | |
function numberFormat(n) { | |
var parts=n.toString().split("."); | |
return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ".") + (parts[1] ? "," + parts[1] : ""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment