Hi.
I know how to convert strings to ints however the strings i want to convert contain leading 0's, i no that ints arent stored like this, however is there anyway around?
e.g. -- "0912"
i want my int to be 0912.
Thanks in advance.
Urema.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
personPosted Aug 21, 2009, 11:40 AM
I have just implemeneted the keys now as varchar, all is grand.
Thanks again
Urema.
Kirtan PatelPosted Aug 21, 2009, 10:59 AM
You can not store Leading Zero in int Column of Database for that you need to use varchar column .
or as another solution
Store the value in database as integer and In Front End Of Application Display it with leading Zero .
you can display this type of result using Query in Front End
select ('0'+Convert(varchar(MAX),Amount)) from Table
personPosted Aug 21, 2009, 10:39 AM
Thats fine for having the ASCII equivalent, however the string, say "0912", that i want converted is actually a primary key, so passing the ascii as a parameter wont work.
Am I right in saying that ints dont store leadng zeros?
Thats basically the problem, i want ints to retain leading zeros when converted from a string to an int.
Any suggestions, Kirtan? Anyone?
Thanks
Urema.
Kirtan PatelPosted Aug 21, 2009, 10:26 AM
Here is What you want .. ( Code Will Convert Each Digit in Their ASCII Equivalent :)
let me know if you are having any difficulties.
private void button1_Click(object sender, EventArgs e)
{
// Convert TextBox Number Charater Array
char[] nums = textBox2.Text.Trim().ToCharArray();
// Varaible for Storing Final Complete Integer Equivalant of Number
string FinalNumber = "";
//Process Each Characters
foreach (char c in nums)
{
FinalNumber += Convert.ToInt32(c);
}
//Store Final Concataed String into Integer
int fnum = Convert.ToInt32(FinalNumber);
//Show it In MessageBox
MessageBox.Show(fnum.ToString());
}
personPosted Aug 21, 2009, 10:13 AM
Thanks Kirtan.
Urema.
Kirtan PatelPosted Aug 21, 2009, 10:11 AM
Explain me What you want as Final Result .
What you will pass and what you want as Out put.. I will Quickly resolve your problem :)