0

我有一个 Rails 视图来按 PERIOD 和 GENERAL LEDGER 显示一个网格,我想显示一个累计总数。然而,在下面的例子中,我在“TOTAL”列中的@cumulative_total 正在四舍五入到最接近的美元,因此没有显示美分,即使它们在 general_ledger 列中正确显示。任何想法我做错了什么?

<% @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>
4

1 回答 1

0

我认为这是因为您在显示时将计费金额转换为“整数”:

@expected_billings.inject(0){|sum,billing| sum+billing.expected_amount.to_i

如果你改变

billing.expected_amount.to_i  

billing.expected_amount.to_f  

它应该工作。

于 2012-05-02T06:53:49.623 回答