Click here to Skip to main content
15,906,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this may seemed very basic...almost ashamed to asked.

But I want to get a double by dividing an integer by another integer.

I want to 0.8 by doing this

but I notice it is not returning the 4/5 only whole numbers.

What I have tried:

double score;
             score = 4/5*100;
Posted
Updated 1-Mar-17 16:19pm
Comments
PIEBALDconsult 1-Mar-17 23:07pm    
score = 4*100.0/5;

double score = (double)4 / (double)5 * 100;
 
Share this answer
 
This should work too
C#
double score= (double)4/5 * 100;
 
Share this answer
 
Comments
Karthik_Mahalingam 1-Mar-17 22:27pm    
Yes :)
Member 9331278 1-Mar-17 22:34pm    
int total;
int num = Convert.ToInt32(txtScore.Text);
if (ViewState["total"] == null)
{
total = num;
}
else
{
total = (int)ViewState["total"] + num;
}
ViewState["total"] = total;

int count;

if (ViewState["count"] == null)
{
count = 1;
}
else
{
count = (int)ViewState["count"] + 1;
}
ViewState["count"] = count;

double score = double((total) / double(count *5)) * 100;
//not working

// score
Label1.Text = total.ToString() + " count " + count.ToString() + " Score " + score.ToString();
Karthik_Mahalingam 1-Mar-17 22:37pm    
what is the value you are getting in score
Member 9331278 1-Mar-17 22:39pm    
0
Member 9331278 1-Mar-17 22:40pm    
0 unless its a whole number

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900