Division not working!?!?

I guess you could call this a noobie problem as well. I’m trying to
divide two numbers by each other…

For example:

<% for element in project.elements %>
Element: <%= horizontal_bar_graph [element.name,
((element.completed_hours / element.hours) * 100)] %>

<% end %>

element.completed_hours == 2
element.hours == 5

(2 / 5) * 100 == 40
However, it returns a total sum of 0. This is incorrect, of course. Why
does it do that?

I tried it with magic numbers instead of the ‘element.whatever’ things,
and 2 / 5 still equalled zero. However, 5 / 2 worked, and so did 0.2 /
0.5. Why is this and how do I get it working??

Thanks in advance, Isaac

On Mon Jul 17, 2006 at 05:27:56AM +0200, Isaac Rowntree wrote:

element.completed_hours == 2
element.hours == 5

(2 / 5) * 100 == 40

it equals 0. (2.0 / 5.0) * 100 == 40.0

(2.0 / 5.0) * 100 == 40.0

im not sure how you cast to float. maybe .to_f? in TCL you dont even
need the .0, just a . is enough…

it equals 0. (2.0 / 5.0) * 100 == 40.0

Sorry? That made no sense at all… If it equals zero, then how do I
make it so that it does what I want?

im not sure how you cast to float. maybe .to_f? in TCL you dont even
need the .0, just a . is enough…

Thanks! Please disregard my last post. .to_f worked like a charm :slight_smile: