Created
October 24, 2018 14:25
-
-
Save swapnilshrikhande/ba5eb277fce292f230f848679439aba0 to your computer and use it in GitHub Desktop.
formatMoney
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
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