in application.helper I was trying to do this.
However it always get 0. Why?
I want something like 37% 49% 98%
Always integer. no float
def evaluate(number_of_people)
percentage = ((number_of_people / 10000) * 100 ).truncate
"<div class='percentage'>Percentage is #{percentage}%</div>".html_safe
end
You’re dividing by an integer, so the result of 3000 / 10000 will be 0.
Divide by 10000.0 instead to force decimal aritmatic.
So change this:
To this:
If your denominator (the 10000 value in this case) is a variable you can use to_f to cast it as a float before dividing.