Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created October 24, 2018 14:25
Show Gist options
  • Save swapnilshrikhande/ba5eb277fce292f230f848679439aba0 to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/ba5eb277fce292f230f848679439aba0 to your computer and use it in GitHub Desktop.
formatMoney
frn.formatMoney = function(){
$("[format-currency]").each(function(){
var currency = function(amount){
return amount.toLocaleString('en-US', { style: 'currency', currency: 'USD' });
}
try{
if( $(this).is("input") ){
var amount = parseFloat( $(this).val() );
if( amount || amount == 0 ){
$(this).val( currency(amount) );
}
} else {
var amount = parseFloat( $(this).text() );
if( amount || amount == 0 ){
$(this).text( currency(amount) );
}
}
} catch(e){
return true;
}
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment