Zero's before number.
-
Hi, In my database table i have column with data like 00987 78960 89760 08123 009876 when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987). How can i do this? int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
-
Hi, In my database table i have column with data like 00987 78960 89760 08123 009876 when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987). How can i do this? int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
00987 is the same as 987. If you read it into an integer variable, then it will remove leading zeros. If you want to display it as it is in the database, then convert it to a string instead of an integer
Between the idea And the reality Between the motion And the act Falls the Shadow
-
Hi, In my database table i have column with data like 00987 78960 89760 08123 009876 when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987). How can i do this? int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
-
Hi, In my database table i have column with data like 00987 78960 89760 08123 009876 when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987). How can i do this? int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
This data is stored as a string in your database. 00987 is exactly the same as 987 - I assume you want it displaying as 00987; in which case you need to use a string to display it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
Hi, In my database table i have column with data like 00987 78960 89760 08123 009876 when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987). How can i do this? int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
Satish - Developer wrote:
when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987)
You have to do nothing (or just review your basic math course material), since
000987 = 987
holds for a integer. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, In my database table i have column with data like 00987 78960 89760 08123 009876 when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987). How can i do this? int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
I suppose that what you really wanted to ask is: how to read a data with leading zeros and don't loose these zeros. You have two possibilities: - Store the number asa string in your application and parse it each time you need it for calculations. - Create a structure which would store a number of zeros (I would do it this way).
internal struct IntWithZeros
{
private int zerosCount, value;public static implicit operator int(IntWithZeros x) { return x.value; } // overload other required operators to preserve zerosCount public static IntWithZeros Parse(string data) { IntWithZeros ret; ret.zerosCount = 0; while (data.Length > ret.zerosCount && data\[ret.zerosCount\] == '0') { ret.zerosCount++; } ret.value = int.Parse(data); return ret; } public override string ToString() { string s = value.ToString(); return s.PadLeft(s.Length + zerosCount, '0'); }
}
Greetings - Jacek Gajek
-
Hi, In my database table i have column with data like 00987 78960 89760 08123 009876 when i read the value(00987) into the integer variable, then it contiana value as 987. I need the value in integer variable as same(00987). How can i do this? int k = Convert.ToInt16(dt.rows[i]["colname]);
G. Satish
-
private void btnUseLeadingZero_Click(object sender, EventArgs e)
{
int MyNumber = 987;
string MyNumberWithLeadingZero = MyNumber.ToString("00000");
MessageBox.Show(MyNumberWithLeadingZero);
//displays 00987
}