0

I am trying to perform division and multiplication between two values and then save them in a double variable.

Multiplication is working fine but division always returning zero ?

Why is it so ?

Here is my Code :

double max_load =(Convert.ToDouble(ddl_gene_desc.SelectedValue)*0.8)*(80/100);

I checked it using the breakpoint that multiplication is fine but (80/100) returning 0.

Can any one please help me ?

Thanks in advance.

Alina Anjum
  • 1,178
  • 6
  • 30
  • 53

3 Answers3

3

The result of 80/100 (both integers) is always 0.

Change it to 80.0/100.0

Tibrogargan
  • 4,508
  • 3
  • 19
  • 38
1

You are dividing two integer values, in this case "80/100" will return 0 because both values are integers and integers do not store a result. Try "80.0/100" to force floating point division.

Krikor Ailanjian
  • 1,842
  • 12
  • 17
1

80 is int, so is 100 - hence integer division. Append 'F' to one of them to make it a float. Or double..

ABuckau
  • 319
  • 4
  • 8