calculate value for gridview label

i need to calculate the value and put in a gridview label. see the code.

error: Input string was not in a correct format.
protected void grdvw_RowDataBound(object sender, GridViewRowEventArgs e)
{
DataRowView drv = (DataRowView)e.Row.DataItem;

if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblLabor = (Label)e.Row.FindControl("lblLabor");
string MainString = drv["reserved_isva"].ToString().Remove(0, 34);
string SearchString = " ";
int FirstChr = MainString.IndexOf(SearchString);
string cleanLabor = MainString.Remove(FirstChr);
lblLabor.Text = String.Format("{0:C2}", cleanLabor); //175.00

Label lblManHours = (Label)e.Row.FindControl("lblManHours");
lblManHours.Text = getMH(lblLabor.Text); //"175.00"
}


public static string getMH(string sLabor) //"175.00"
    {
        int iLabor = Convert.ToInt32(sLabor); //errors here
        int iValue = iLabor / 60;
        string sValue = Convert.ToString(iValue); //should equal "2.91666"
        return sValue;
    }

Open in new window

vicominAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Edgard YamashitaSystems AnalystCommented:
try to convert to decimal first eg:

int iLabor = Convert.ToInt32(Convert.ToDecimal(sLabor));
0
Edgard YamashitaSystems AnalystCommented:
oh also in here:

        int iValue = iLabor / 60;
        string sValue = Convert.ToString(iValue); //should equal "2.91666"
        return sValue;


it will not equal to 2.91666 since your dividing and setting the value in a int property not a decimal one maybe you should try like this:


        string sValue = Decimal.Divide(iLabor, 60).ToString();
        return sValue;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vicominAuthor Commented:
slight modification
public static string getMH(string sLabor, string sQty) //"175.00", "2"
    {
        int iLabor = Convert.ToInt32(Convert.ToDecimal(sLabor));
        int iQty = Convert.ToInt32(sQty);
        int iValue = (iLabor * iQty);
        string sValue = Decimal.Divide(iValue, 60).ToString();//5.8333333333333333333333333333
        //round up so the above would be 6
        return sValue;
    }

Open in new window

0
princeatapiCommented:
may be you could use this function instead
public static string getMH(string sLabor) //"175.00"
    {
        double  iLabor = Convert.ToDouble(sLabor); //errors here
        double iValue = iLabor / 60.0;
        string sValue = Convert.ToString(iValue); //should equal "2.91666"
        return sValue;
    }
0
vicominAuthor Commented:
string sValue = System.Math.Round(Decimal.Divide(iValue, 60)).ToString();
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.