Rather than an “8.75” returned.
Which method? Thanks.
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.
If I’m not completely wrong,
35/4always evaluates to 8. Even inyou will get this result (as double, i.e.
8.0). This is because35and4are both integers and therefore integer division is applied. The expression is first evaluated as integer and only the result is cast to a double value.On the other hand, if you want the correct result
8.75you’ ll have to writein order to force floating point division to be applied. This is a common pitfall by the way.
Of course, if you have double values, like in
you need to either explicitely cast to an
intor useMath.floor()as suggested in previous posts.