Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7687955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:48:56+00:00 2026-05-31T19:48:56+00:00

In Ruby on Rails 3.2.1, I am iterating over the value pairs of a

  • 0

In Ruby on Rails 3.2.1, I am iterating over the value pairs of a hash, where trsesh_mode is the key and trsesh_count is the value. I want to divide the trsesh_count for each mode of exercise the user had done by the total number of training sessions that user has completed.

Here is the iteration of the hash:

@trsesh_counts.each do |trsesh_mode, trsesh_count|
     count = @user_name.training_sessions.count 

     @weight =  trsesh_count / count

@weight is returning 0 for each value iterated into the calculation.

If I convert this calculation into a string and embed the ruby variables like so:

<% = "(#{trsesh_count}) / (#{count})" %>

… I get this output in my view:

(7) / (20)
(12) / (20)
(1) / (20)

where 20 is the count and the numerators are the iterated trsesh_count values.

If it helps, the trsesh_count values are FixNum.

My question is: Why am I getting 0 for output when performing the calculation above (@weight = …)? How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:48:58+00:00Added an answer on May 31, 2026 at 7:48 pm

    You are dividing integer numbers, so that the integer division result is zero.

    Force one number to float, and it should work fine, like this:

    @weight =  trsesh_count.to_f / count
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are creating a system in Ruby on Rails and we want to be
I'm new to Rails (and ruby). What is the standard way of iterating through
I've got an existing production Ruby/Rails app that I want to migrate to MongoDB
I am modifying a Ruby Rails application - Redmine. I want to modify a
As a Ruby/Rails non-pro, I often want to check out the code for a
Extreme Ruby/Rails novice here: I'm trying to link_to a search action for each individual
I'm having an issue integrating flex with ruby on rails. I get this error:
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
I am using Sunspot (Ruby/Rails) on top of SOLR in my webapp. Now I
What are the best Ruby / Rails book available right now ? Note :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.