在递增值时,在开头保持为零 [英] keep zero at the begining when incrementing the value

查看:92
本文介绍了在递增值时,在开头保持为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以这样的文本框中的给定数量递增组合框值



 十进制 j = Convert.ToDecimal(cbxgetSN.Text); 

Int64 k = Convert.ToInt64(textBoxQuantitySN.Text);

for int i = 0 ; i < k; i ++)
{

SerialListBox.Items.Add( RET +(j + i + 1 ) );

}



和这个

但是如果我的组合框值是000123那么它只增加123

目前正在做。

123

124

125

126

i想要它就像。

000123

000124

000125

请帮助

解决方案

您需要将其格式化为字符串,而不是将其保留为int。 Ints没有前导零的概念,所以除非你格式化,否则它不能在前面保留任何零。

尝试:

  string  s = myIntValue.ToString(  D6\" ); 


i am incrementing combo box value with given quantity in textbox like this

decimal j = Convert.ToDecimal(cbxgetSN.Text);

Int64 k = Convert.ToInt64(textBoxQuantitySN.Text);

for (int i = 0; i < k; i++)
{

   SerialListBox.Items.Add("RET"+(j + i + 1));

}


and this
but if my combobox value is 000123 then it only increment 123
at the moment its doing.
123
124
125
126
i want it to incement like.
000123
000124
000125
please help

解决方案

You need to format it as a string, rather than leave it as an int. Ints have no concept of leading zeros, so unless you format it, it can''t "keep any zeros" at the front.
Try:

string s = myIntValue.ToString("D6");


这篇关于在递增值时,在开头保持为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆