I have a some numbers stored in the database.
>> t = Total.first
=> #<Total id: 1, profit: 1058, number: 17, fees: 204, created_at: "2012-01-12 06:44:30", updated_at: "2012-01-12 06:51:13">
I want to perform division on one of the integers (an integer that will be updated frequently) and have the division on the newly updated integer. I basically just want to know what percent the profit is of 26,000
>> t.profit
=> 1058
>> t.profit / 26000
=> 0
>> t.profit.to_i / 26000
=> 0
I was hoping it would be as easy as something like this
def index
@t = Total.first
@x = @t.profit / 26000
end
View
<%= @x %>
but it’s not working, as the console suggested it wouldn’t. Any hints?
It’s an integer division, so the result is rounded. Convert one of your operands to float.
To round that to two decimal places use something like this: