• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1059
  • Last Modified:

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

0
CharlieDev
Asked:
CharlieDev
  • 3
1 Solution
 
Shanmuga SundaramCommented:
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
 
CharlieDevAuthor Commented:
Thanks for that :)
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now