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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Priya LingeRank #785 · 2.9K reputationPosted Sep 19, 2011, 11:37 PM EDT
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.
VulpesRank #55 · 29.2K reputationPosted Sep 20, 2011, 1:24 AM EDT
http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx
Marvin kakuruRank #3,979 · 374 reputationPosted Sep 20, 2011, 2:23 AM EDT
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
karthik v115 reputationPosted Sep 20, 2011, 5:11 AM EDT
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);
}
Hemant KumarRank #1,202 · 1.5K reputationPosted Sep 20, 2011, 6:15 AM EDT
String.Format("{0:#,#}", text)
Hope this will help you :-)