Skip to content

Instantly share code, notes, and snippets.

@oraculum
Created October 25, 2012 06:12
Show Gist options
  • Save oraculum/3950800 to your computer and use it in GitHub Desktop.
Save oraculum/3950800 to your computer and use it in GitHub Desktop.
Formatando valores monetários em javascript
$("#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