Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
hey

i I want a to store a value

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



it prints 1

but i I want 0000001

plz help

[edit]pre tag for C# code added. Capitalization corrected. - PES[/edit]
Posted
Updated 29-Feb-12 22:57pm
v2

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

—SA
 
Share this answer
 
Comments
Chandrakantt 1-Mar-12 4:22am    
Yes you are correct Its the exact reason behind it.
Sergey Alexandrovich Kryukov 1-Mar-12 4:43am    
Any reason for vote of 1?
--SA
Chandrakantt 1-Mar-12 4:47am    
Ohh Sorry, that was pressed unintentionally. I tried to change that afterwards but wan not able to do that time. Wow I was able to change it now... :)
Sergey Alexandrovich Kryukov 1-Mar-12 4:51am    
No problem, thanks for a fix. :-)
--SA
sw.Write(string.Format("{0:0000000}", i + 1));
 
Share this answer
 
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

C#
int count = 0;
count = 000000 + i; //where i=1
string customFormat = "000000";
string strVal = count.ToString(customFormat);
sw.write(strVal);
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 1-Mar-12 4:19am    
Correct, but OP would need at least some explanation, because of huge confusion with the very basic things. I voted 4.
Tried add my own answer, but... please see if you are curious...
--SA
Change your database type to string.
 
Share this answer
 
Make use of the String.Format()[^] features to convert an integer value into a fixed length string.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900