存储值0000001但存储1 [英] storing value 0000001 but it store 1

查看:73
本文介绍了存储值0000001但存储1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i 我要 a 存储值

hey

i I want a to store a value

int count=0;
count=000000+i;  //where i=1 
sw.write(count);




它会打印1

但是 i 我想要0000001

请帮助

[edit]添加了C#代码的预标签.大写字母已更正. -PES [/edit]




it prints 1

but i I want 0000001

plz help

[edit]pre tag for C# code added. Capitalization corrected. - PES[/edit]

推荐答案

整数值1和00000001完全相同.不要将数字值与它们的字符串表示形式混淆.

—SA
Integer values 1 and 00000001 are exactly the same. Don''t mix up numeric values with their string representations.

—SA


sw.Write(string.Format("{0:0000000}",i + 1));
sw.Write(string.Format("{0:0000000}", i + 1));


它不能存储为整数值...如果要将其存储在此模式中,则必须将其存储在字符串中.

您可以使用以下命令

it cannot be stored in an integer value... You have to store it in string if you want it to be stored in this pattern.

You can use below command

int count = 0;
count = 000000 + i; //where i=1
string customFormat = "000000";
string strVal = count.ToString(customFormat);
sw.write(strVal);


这篇关于存储值0000001但存储1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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