How do you divide two integers and get a double or float answer in C?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need to cast one or the other to a
floatordouble.Of course, make sure that you are store the result of the division in a
doubleorfloat! It doesn’t do you any good if you store the result in anotherint.Regarding @Chad’s comment (“
[tailsPerField setIntValue:tailsPer]“):Don’t pass a double or float to
setIntValuewhen you havesetDoubleValue, etc. available. That’s probably the same issue as I mentioned in the comment, where you aren’t using an explicit cast, and you’re getting an invalid value because a double is being read as an int.For example, on my system, the file:
outputs:
because the double was attempted to be read as an int.