0

I have a brief question... pretty new to rails, and I was wondering if you could help me with an issue that I'm having in code. I have a set of input boxes (it's an online app that asks for revenues and expenses) where I would like to format the currency. I've been using the following line of code for other independent input boxes (text_fields) within the app, but for some reason, it wont work when i try to add it to the income statement fields

code I have been using:

= f.text_field :user_nummber, :value=>number_to_currency(f.object.user_number)

the area of code i've been having issues with:

 = f.fields_for :income_statements do |ff|
        .section_total.income_statement{ :id => "income_statement_#{ff.object.year}" }
          = ff.hidden_field :id
          = ff.hidden_field :year
          %h3.financials_year= ff.object.year

          .financials_data
            .section
              %h2.green_text Revenue
              %div{:class => "label_rightalign_investor field"}
                = ff.label :net_sales
                = ff.text_field :net_sales, :value=>number_to_currency(ff.object.net_sales), :class => 'add'
              %div{:class => "label_rightalign_investor field"}
                = ff.label :interest_income
                = ff.text_field :interest_income, :value=>number_to_currency(ff.object.interest_income), :class => 'add'
              %div{:class => "label_rightalign_investor field", :style => 'font-weight: bold' }
                = label_tag 'Total'
                = text_field_tag 'total_revenue', '', :class => 'calculate add_total', :readonly => true

Please note that the final total_revenue field calculates the values with class:add (net sales & interest income)

Any help in what i'm doing wrong, and why my text_fields (input box) does not display values in the following format: $x,xxx.00 would be appreciated.

I sincerely thank you for your help and time!

slovak_100
  • 782
  • 2
  • 10
  • 33
  • What IS being displayed instead? – Thilo Aug 05 '11 at 02:39
  • Nothing... just the standard numbers... if i type 200000 i would like for it to display $200,000.00 or at least $200,000, instead it simply displays 200000 – slovak_100 Aug 05 '11 at 04:17
  • Is it just the last text field (total_revenue) that displays this behavior, or all text fields in the fields_for section? – Thilo Aug 05 '11 at 04:27
  • @Thilo, all the text fields in the fields_for section. I'm aware that I did not include the :value property to the last field--I should have mentioned that, sorry. – slovak_100 Aug 05 '11 at 04:50
  • I know this is very old and you probably solved it, but could it be something as silly as a typo? In the first text_field you have `user_nummber` instead of `user_number` – GiH Mar 26 '13 at 03:34

1 Answers1

0

Try add the precision parameter like this:

<%= f.text_field :user_number, :value => number_to_currency(f.object.user_number, :precision => 3) %>

Check here for more details: http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency

Hope it helps you somehow!

Kleber S.
  • 8,110
  • 6
  • 43
  • 69
  • @ Kleber: Thanks for the link mate; however, my issue actually is that it's not displaying anything at all... not just the location or accuracy of the decimal point. – slovak_100 Aug 05 '11 at 18:51