Click here to Skip to main content
15,881,938 members
Home / Discussions / C#
   

C#

 
AnswerRe: Online Database Pin
PIEBALDconsult12-Apr-11 2:48
mvePIEBALDconsult12-Apr-11 2:48 
QuestionNetwork Transaction Pin
nEar_mO11-Apr-11 22:59
nEar_mO11-Apr-11 22:59 
AnswerRe: Network Transaction Pin
OriginalGriff11-Apr-11 23:53
mveOriginalGriff11-Apr-11 23:53 
QuestionWorks from Visual Studio only Pin
D_Ana11-Apr-11 9:20
D_Ana11-Apr-11 9:20 
AnswerRe: Works from Visual Studio only Pin
Pete O'Hanlon11-Apr-11 9:51
mvePete O'Hanlon11-Apr-11 9:51 
AnswerRe: Works from Visual Studio only Pin
Wayne Gaylard11-Apr-11 22:25
professionalWayne Gaylard11-Apr-11 22:25 
GeneralRe: Works from Visual Studio only Pin
D_Ana13-Apr-11 6:31
D_Ana13-Apr-11 6:31 
QuestionHow do I cast a double to an int? Pin
Justiin126511-Apr-11 7:18
Justiin126511-Apr-11 7:18 
Hi,

I have a program for work 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 intvaluetoconvert = Convert.toint32; I'm doing that , but still get the error Cannot implicitly convert type 'double to int. An explicit conversion exists(are you missing a cast?) What am I doing wrong? Can someone please help? Thank you.

Justin

Here's some of my code to look at?

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);
}

return Refurb_Rate;
}
AnswerRe: How do I cast a double to an int? Pin
Eddy Vluggen11-Apr-11 7:25
professionalEddy Vluggen11-Apr-11 7:25 
GeneralRe: How do I cast a double to an int? Pin
Justiin126511-Apr-11 7:44
Justiin126511-Apr-11 7:44 
AnswerRe: How do I cast a double to an int? Pin
Eddy Vluggen11-Apr-11 8:09
professionalEddy Vluggen11-Apr-11 8:09 
GeneralRe: How do I cast a double to an int? Pin
David198711-Apr-11 7:35
David198711-Apr-11 7:35 
GeneralRe: How do I cast a double to an int? Pin
Justiin126511-Apr-11 7:45
Justiin126511-Apr-11 7:45 
GeneralRe: How do I cast a double to an int? Pin
AspDotNetDev11-Apr-11 8:06
protectorAspDotNetDev11-Apr-11 8:06 
AnswerRe: How do I cast a double to an int? Pin
Alan N11-Apr-11 7:47
Alan N11-Apr-11 7:47 
AnswerRe: How do I cast a double to an int? Pin
Luc Pattyn11-Apr-11 8:09
sitebuilderLuc Pattyn11-Apr-11 8:09 
GeneralRe: How do I cast a double to an int? Pin
Justiin126511-Apr-11 8:14
Justiin126511-Apr-11 8:14 
GeneralRe: How do I cast a double to an int? Pin
AspDotNetDev11-Apr-11 8:29
protectorAspDotNetDev11-Apr-11 8:29 
QuestionPRE Tagged Pin
AspDotNetDev11-Apr-11 8:11
protectorAspDotNetDev11-Apr-11 8:11 
AnswerRe: PRE Tagged Pin
Luc Pattyn11-Apr-11 8:16
sitebuilderLuc Pattyn11-Apr-11 8:16 
AnswerRe: How do I cast a double to an int? [modified] Pin
Luc Pattyn11-Apr-11 8:14
sitebuilderLuc Pattyn11-Apr-11 8:14 
GeneralRe: How do I cast a double to an int? Pin
AspDotNetDev11-Apr-11 8:21
protectorAspDotNetDev11-Apr-11 8:21 
GeneralRe: How do I cast a double to an int? Pin
Luc Pattyn11-Apr-11 8:27
sitebuilderLuc Pattyn11-Apr-11 8:27 
GeneralRe: How do I cast a double to an int? Pin
David198711-Apr-11 8:45
David198711-Apr-11 8:45 
AnswerRe: How do I cast a double to an int? Pin
Luc Pattyn11-Apr-11 8:55
sitebuilderLuc Pattyn11-Apr-11 8:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.