seemingly simple expression yields embarrassing result. Help!

Write your question here.
pls can anybody help me with why (212-32)/100 as shown below yield 1 instead of 1.8.
1
2
  float nfactor;
  nfactor = (212-32)/(100);
You're doing integer division. The result is converted to a float only when the assignment is done. Try this instead:
 
  nfactor = (212-32)/(100.0);  // Note the decimal place which makes the divisor a double 

Hi,
You should write your expression like this :
(212.0-32.0)/100.0
Because if they are integers, there are quotient & remainder. But if they are double (eg: 212.0), none of these things matters anymore.
And you also use a double variable to retrieve the result of the expression, like this :
double a = (212.0-32.0)/(100.0);
Does that help? :)
Thanks a lot. it skipped my mind... a times u just forget those small things...
Topic archived. No new replies allowed.