0
我有一個Rails視圖來顯示PERIOD和GENERAL LEDGER的網格,我想顯示累計總數。但是,在下面的情況下,我的@cumulative_total在「TOTAL」列中四捨五入到最接近的美元,因此即使在general_ledger列中正確顯示,也不會顯示美分。任何想法我做錯了什麼?Rails 3視圖 - 向上舍入
<% @cumulative_total = 0 %>
<div id="gl_crosstab">
<table>
<tr>
<th>Period</th>
<% @general_ledgers.each do |g| %>
<th><%= g.general_ledger_number %></th>
<% end %>
<th>Total</th>
<th>% Expended</th>
</tr>
<% @expected_billings.group_by(&:period_id).each do |eb| %>
<tr>
<td><%= eb[1].first.period.pe_number %></td>
<% eb[1].each do|p| %>
<td><%= number_to_currency(p.expected_amount) %></td>
<% end %>
<td>
<% @cumulative_total = @cumulative_total + eb[1].inject(0){|sum,billing| sum+billing.expected_amount.to_i} %>
<%= number_to_currency(@cumulative_total) %> </td>
<td><%= number_to_currency((@cumulative_total/@sla.project_total)*100) %> % </td>
</tr>
<% end %>
<tr>
<td><b>Total Budget</td>
<% @total_expected_billings.each do |teb| %>
<td><b><%= number_to_currency(teb[1].inject(0){|sum,billing| sum+billing.expected_amount.to_i}) %></td>
<% end %>
<td><b><%= number_to_currency(@expected_billings.inject(0){|sum,billing| sum+billing.expected_amount.to_i}) %> </td>
<td><b><%= number_to_currency((@expected_billings.inject(0){|sum,billing| sum+billing.expected_amount.to_i}/@sla.project_total)*100) %> % </b></td>
</tr>
</table>
</div>
謝謝!這個小小的'f'就是它所需要的! :) –