设置文本框以显示美元金额 [英] Setting Textbox to Display Dollar amount
本文介绍了设置文本框以显示美元金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有办法设置文本框以显示美元货币金额吗?我有文本框来填充数据库中的数字。这是我的代码:
IS there a way for me to set the textbox to display dollar currency amount? I have the textboxes to populate the numbers from the database. Here is my code:
SqlDataReader dr = scmd.ExecuteReader();
if (dr.Read())
{
TextBoxTA1.Text = dr["TOTASSETS"].ToString();
TextBoxTL1.Text = dr["TOTLIABILITY"].ToString();
TextBoxUNA1.Text = dr["UNRNETASSETS"].ToString();
TextBoxPRNA1.Text = dr["NonExppermresAssets"].ToString();
TextBoxTR1.Text = dr["TotalRev"].ToString();
TextBoxTFN1.Text = dr["TuitFees"].ToString();
TextBoxCD1.Text = dr["CurrDebt"].ToString();
TextBoxLDT1.Text = dr["LongTermDebt"].ToString();
int a = Convert.ToInt32(TextBoxTA1.Text);
int b = Convert.ToInt32(TextBoxTL1.Text);
TextBoxTNA1.Text = Convert.ToString(a - b);
int a1 = Convert.ToInt32(TextBoxUNA1.Text);
int b1 = Convert.ToInt32(TextBoxPRNA1.Text);
TextBoxTNAS1.Text = Convert.ToString(a1 + b1);
}
dr.Close();
con.Close();
推荐答案
可能string.Format({0:c },value)
会为你做的。检查如何使用它:
显示的货币格式 [ ^ ]
字符串格式,货币双值未正确显示 [ ^ ]
Possiblystring.Format("{0:c}", value)
would do the trick for you.Check how to use that:
Currency format for display[^]
String Formatting with currency double values not displaying correctly[^]
ToString的格式如下:
ToString can be formatted as in:
TextBox1.Text = floatVar.ToString("#0.00"); //suppose you have a float or double variable
这篇关于设置文本框以显示美元金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文