加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 显示带前导零的数字文本框值

发布时间:2020-12-15 19:46:53 所属栏目:百科 来源:网络整理
导读:我有3个文本框值: no of requests = 2court fee = 60claim amount = 200 我的客户要求他们希望展示: 我试过这个,但没有得到这些价值观.我不知道我哪里错了. no of requests = 00002; // 5 characterscourt fee = 0000 no of requests = 2court fee = 60cla
我有3个文本框值:

no of requests = 2
court fee = 60
claim amount = 200

我的客户要求他们希望展示:

我试过这个,但没有得到这些价值观.我不知道我哪里错了.


no of requests = 00002; // 5 characters
court fee = 0000
no of requests = 2
court fee = 60
claim amount = 200
no of requests = 2 court fee = 60 claim amount = 200; // 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

解决方法

不要对整数使用小数.使用int表示整数,小数表示货币金额等.如果你想要前导零,那么你可以这样做:

var str = number.ToString("00000"); // At least five digits with leading zeroes if required.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读