convert string to an integer

Hi,
I have a gridview table and i want to get the total of one of the columns. I need to convert the string thats in the field into an integer to add it up.
Can anyone suggest how i change this  " float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]) ;  " so that
the total will be an integer.

Thanks



int total;
 
    public void sumRows(Object src, GridViewRowEventArgs e)
    {
       
 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            TableCellCollection cells = e.Row.Cells;
            total += float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]) ; 
            cells[cells.Count - 1].Text = string.Format("{0:n}",
            float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]));
        }
    }

Open in new window

CharlieDevAsked:
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.

Shanmuga SundaramDirector of Software EngineeringCommented:
Haven't you tried using int.parse?
0
CharlieDevAuthor Commented:
I dont know where to put it in my code, i'm trying to figure out where to put it now. Any suggestions be great!!!
0
CharlieDevAuthor Commented:
I'm trying '  total += Int32.Parse(float.Parse(cells[cells.Count - 1].Text.Split(' ')[0])) ;  '
but  i get an error   " The best overloaded method match for 'int.Parse(string)' has some invalid arguments"
0
angus_young_acdcCommented:
Thats because part of what you're trying to convert isn't a string.  

Try the following:
float.Parse(cells[cells.Count - 1].Text.Split(' ')[0]).ToString());
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
CharlieDevAuthor Commented:
Thanks for that :)
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
.NET Programming

From novice to tech pro — start learning today.