$('* div').each(function () { var item = $(this).text(); var num = Number(item).toLocaleString('en'); if (Number(item) < 0) { num = num.replace('-',''); $(this).addClass('negMoney'); }else{ $(this).addClass('enMoney'); } $(this).text(num); });
<h3>Format Currency</h3> <!-- Format numbers to currency using a bit of JavaScript and CSS Source: http://ozkary.blogspot.com/ Date: 04/27/2014 --> <div id="stmt0">250</div> <hr/> <div id="stmt1">2500</div> <hr/> <div id="stmt2">25000</div> <hr/> <div id="stmt3">-250009</div> <hr/> <div id="stmt4">2500000</div> <hr/>
.enMoney::before { content:"$"; } .negMoney { color:red; } div.negMoney::before { content:'($'; } div.negMoney::after { content:')'; }