Convert the amount entered in the textbox to US format

Script used to convert the entered textbox value to US format is as follows

<script type="text/javascript">

function formatCurrency(usFormat) {

usFormat = usFormat.toString().replace(/\$|\,/g,'');

if(isNaN(usFormat))

usFormat = "0";

sign = (usFormat == (usFormat = Math.abs(usFormat)));

usFormat = Math.floor(usFormat*100+0.50000000001);

cents = usFormat%100;

usFormat = Math.floor(usFormat/100).toString();

if(cents<10)

cents = "0" + cents;

for (var i = 0; i < Math.floor((usFormat.length-(1+i))/3); i++)

usFormat = usFormat.substring(0,usFormat.length-(4*i+3))+','+

usFormat.substring(usFormat.length-(4*i+3));

return (((sign)?'':'-') + '$' + usFormat + '.' + cents);

}

</script>


This is what you have to do for Textbox

 <asp:TextBox ID="TextBox1" runat="server" Style="left: 411px; position: absolute;
top: 186px" onBlur="this.value=formatCurrency(this.value);"></asp:TextBox>

Next Recommended Reading Enter only numbers in textbox in ASP.Net