hi all,
hope your alright. i am trying to format a textbox.text to "##,##,##" so that as i type a currency value for example 3000 the code produces 3,000.
thanks again.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hemant KumarPosted Sep 20, 2011, 10:15 AM
String.Format("{0:#,#}", text)
Hope this will help you :-)
karthik vPosted Sep 20, 2011, 9:11 AM
function formatCurrency(num)
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}
Marvin kakuruPosted Sep 20, 2011, 6:23 AM
i needed my textbox7.text to produce a money value for example " 3,000 " as i type 3000 into this very textbox.
i have used your code this way, see below
private void textBox7_TextChanged(object sender, EventArgs e)
{
String.Format("{0:#,0}", textBox7.Text);
however this code has got effect on what i type into the textbox.
thanks again
VulpesPosted Sep 20, 2011, 5:24 AM
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx
Priya LingePosted Sep 20, 2011, 3:37 AM
Please check this.
string tempStr = String.Format("{0:#,0}", 3000);
MessageBox.Show(tempStr.ToString());
string tempStr = String.Format("{0:#,0}", txtfirst.Text);
It will give u output as 3,000.
Hope this will help you.
Thanks.