Skip to content

Instantly share code, notes, and snippets.

@felipemorais
Created February 19, 2013 20:48
Show Gist options
  • Save felipemorais/4989763 to your computer and use it in GitHub Desktop.
Save felipemorais/4989763 to your computer and use it in GitHub Desktop.
Format Currency - BRL
function formatCurrency( value ) {
var exit = [];
var i;
value = parseFloat( value );
value = value.toString().split("").reverse();
for( i = 0; i < value.length; i++ ) {
if( i == 2 ) {
exit.push( "," );
} else if ( ( i - 2 ) % 3 == 0 ) {
exit.push( "." );
}
exit.push( value[ i ] );
};
if(exit[0] == "."){
exit.shift();
}
return exit.reverse().join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment