function addCommas(clientID)
{
var nStr = document.getElementById(clientID.id).value;
nStr += '';
x = nStr.split('.');
if (!x[0] )
{
x[0] = "0";
}
x1 = x[0];
if (!x[1] )
{
x[1] = "00";
}
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
document.getElementById(clientID.id).value = x1 + x2;
return true;
}
function removeCommas(clientID)
{
var nStr = document.getElementById(clientID.id).value;
nStr = nStr.replace(/,/g, '');
document.getElementById(clientID.id).value = nStr;
$(clientID).select();
return true;
}
And call it on onfocus
<asp:TextBox ID="txtbxId" runat="server" onfocus="removeCommas(this)" OnBlur="addCommas(this)"></asp:TextBox>
This will be format your number with commas and decimals
be carefull while accessing textbox value, remove commas before use