Wednesday, August 7, 2013

Formatting String With LEading Zero's

Formatting String With LEading Zero's

I am trying to convert an object (coming from a SQL server), into a
integer so I can format the number to have the correct amount of zero's in
front of it.
For example:
If I were to have 25.6, I would need it to be 0025.6.
Now I have looked online on how to do this, but the methods that I have
seen people post are not working for me. I am not entirely sure why. I am
trying to format GlobalVariables.grossweightafter. I read the value
GlobalVariables.grossweight from the SQL server, but then when I TryParse
it, it loses its value. The code I have is below:
while (TransferRecord.Read())
{
//Pulling data from the SQL server. getting data for every
line of code as specified.
GlobalVariables.baledate =
TransferRecord["keyprinter_datetime"];
GlobalVariables.baleline = TransferRecord["pulp_line_id"];
GlobalVariables.baleid = TransferRecord["bale_id"];
GlobalVariables.grossweight =
TransferRecord["bale_gross_weight"];
GlobalVariables.grossweightflag =
TransferRecord["gross_value_flag"];
GlobalVariables.baleairdrypercent =
TransferRecord["bale_airdry_pct"];
GlobalVariables.airdryflag =
TransferRecord["airdry_value_flag"];
//Converting the date, and the baleid to fit in the string.
DateTime.TryParse(GlobalVariables.baledate.ToString(), out
GlobalVariables.baledateafter);
int.TryParse(GlobalVariables.baleid.ToString(), out
GlobalVariables.baleidafter);
int.TryParse(GlobalVariables.grossweight.ToString(), out
GlobalVariables.grossweightafter);
GlobalVariables.grossweightafter.ToString("0000.0");
//Calling the WriteData method.
WriteData();
}
So I was wondering if anyone can catch what I am doing wrong, or they can
help me out on the correct way to go about this.

No comments:

Post a Comment