title: How do I cast a double to an int?
body: <p>I have a program that uses a formula to calculate the refurb on a unit (parts replaced on cableboxes that were damaged) divided by total units (cableboxes that went through refurb, but did not have any parts replaced). I looked up casting online, and the format for it is:</p>
  
  <pre><code>int valuetoconvert = Convert.ToInt32;
  </code></pre>
  
  <p>I'm doing that, but I still get the following error:</p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'double to int. An explicit conversion exists(are you missing a cast?) </p>
  </blockquote>
  
  <p>What am I doing wrong? Can someone please help? Thank you.</p>
  
  <p>Here's some of my code:</p>
  
  <pre><code>private int GetRefurbRate()
  {
  string sql = "";
  double Refurb_Rate;
  int totalRefurb = 0;
  int totalUnits = 0;
  string error_msg = "";
  
  
  sql = "SELECT COUNT(rp.repair_ord) " +
  "FROM " + schema + ".repair_part rp " +
  "WHERE rp.repair_ord = '" + repair_ord + "' ";
  while (true)
  {
  if (!myDb.RunSql(sql, true))
  {
  error_msg = "DBError for getting Refurb Rate";
  break;
  }
  if (myDb.dbRdr.HasRows)
  {
  if (myDb.dbRdr.Read())
  {
  try //Try and Catch are here b/c I originally had everything ints, and and they just caught the 0 exception.
  {
  
  Refurb_Rate = Convert.ToInt32( totalRefurb / totalUnits * 100); //This is where I try to perform the cast.
  
  }
  catch (Exception e)
  {
  Console.WriteLine(e);
  }
  
  }
  
  //int Refurb_Rate = Convert.ToInt32(Refurb_Rate);
  }
  
  break;
  }
  myDb.dbRdr.Close();
  
  if (error_msg != String.Empty)
  {
  MessageBox.Show(error_msg, "Get Refurb Rate",
  MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
  }
  </code></pre>