Beginner issue with floats and doubles

I'm writing a simple algebraic expression and I'm trying to express the answer in a variable. I know the answer is going to be a decimal so I've declared the variable as a float (I've also tried declaring it as a double), but the program always says my variable is 0 after being run.
Thank you

 
  float gradient = ((rightColor.green - leftColor.green) / cols);


cols is an integer variable, as are the rightColor.green and leftColor.green variables.
Get your code to write out the values of rightColor.green and leftColor.green and cols before this statement.

Even if these values are OK, then, because the RHS is worked out before being assigned to a float, integer division may be performed. (e.g 2/4 -> 0, but 2/4.0 -> 0.5) If this is the case then you will have to cast numerator or denominator to a float first.
Topic archived. No new replies allowed.