Weird calculation problem

  • Thread starter Thread starter Gas
  • Start date Start date
G

Gas

I am new to C#, I want to perfoem a calculation and I have a weird out come
from the app.

Here is the code

double percentage = 0;

percentage = ctrl1.Height / (ctrl1.Height+ ctrl2.Height)

when I try to output the percentage, it is always 0.
(ctrl1.Height and ctrl2.Height are positive value)

anyone can give me some help here?


Gas
 
Gas

all computations are being done using integer math - and the results will be
either 0 or 1, then stored in the double.

consider casting one variable to a double - and that will get the entire
expression to be evaluated using floating point math instead of integer
math. try something like this:

double percentage = 0;
percentage = (double)ctrl1.Height / (ctrl1.Height+ ctrl2.Height)


regards
roy
 
Back
Top