Reputation: 3307
Hi I have a table cell that outputs total cost. Right now it just writes it in regular number i.e 234344 I want to change it so it can display currency format i.e $3,345,1.00
<td><input type="text" class="" id="totalCost" name="totalCose" value="{{=totalCost}}" /><td/>
I can use solution in jquery, html or in asp.net either one. I tried using this jquery plugin http://www.decorplanit.com/plugin/ but this works for input box while I am getting values from database. Please let me know wasted alot of time and no solution. THANKS
Upvotes: 0
Views: 134
Reputation: 9923
This is what I use.
function format_num(number) {
number += '';
x = number.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return "$" + x1 + x2;
}
So...
Input = 100000
Output = $100,000
Upvotes: 1