I’m currently trying to divide counts["email"] a hash containing the number 82,000 by a variable total which contains the value 1.3 million.
When I run puts counts["email"]/total I get 0.
Why can’t I perform division on these?
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.
Because that’s how Ruby works: when you divide integer to integer, you get an integer. In this case that’ll be 0, because it’s the integer part of the result.
To get the float result, just tell Ruby that you actually need a float! There’re many ways to do it, I guess the most simple would be just convert one of the operand to Float…