我有 3 个文本框值:
no of requests = 2
court fee = 60
claim amount = 200
我的客户要求希望他们显示:
no of requests = 00002; // 5 characters
court fee = 000006000; // 9 characters
claim amount = 0000020000; // 10 characters
我试过这个,但没有得到这些值。我不知道我哪里出错了。
decimal requests = 0;
decimal CFee = 0;
decimal CLAIMAMT = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
CFee += Convert.ToDecimal(dataGridView1.Rows[i].Cells["CFee"].Value) / 100 * dataGridView1.RowCount;
CLAIMAMT += Convert.ToDecimal(dataGridView1.Rows[i].Cells["CLAIMAMT"].Value) / 100 ;
requests = Convert.ToInt16(dataGridView1.RowCount.ToString());
}
textBox3.Text = CFee.ToString();//court fee
textBox4.Text = CLAIMAMT.ToString();//claim amoiunt
textBox2.Text = requests.ToString();//no
最佳答案
不要对整数使用小数。使用整数表示整数,使用小数表示货币金额等。如果你想要前导零,那么你可以这样做:
var str = number.ToString("00000"); // At least five digits with leading zeroes if required.
关于c# - 显示带有前导零的数字文本框值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22065232/