无法在 Rails 3 的文本字段中显示小数
我有一个简短的问题......对 Rails 相当陌生,我想知道你是否可以帮助我解决我在代码中遇到的问题。我有一组输入框(这是一个询问收入和支出的在线应用程序),我想在其中设置货币格式。我一直在应用程序内的其他独立输入框(text_fields)中使用以下代码行,但由于某种原因,当我尝试将其添加到
我一直使用的损益表字段代码
= f.text_field :user_nummber, :value=>number_to_currency(f.object.user_number)
中 时,它不会工作:我一直遇到问题的代码:
= 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
请注意,最终的 Total_revenue 字段使用 class:add (净销售额和利息收入) 计算值
对于我做错的事情以及为什么我的 text_fields (输入框) 这样做有任何帮助不显示值以下格式:$x,xxx.00 将不胜感激。
我衷心感谢您的帮助和时间!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试添加精度参数,如下所示:
查看此处了解更多详细信息:
http://api.rubyonrails.org/classes/ActionView /Helpers/NumberHelper.html#method-i-number_to_currency
希望它能对您有所帮助!
Try add the precision parameter like this:
Check here for more details:
http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html#method-i-number_to_currency
Hope it helps you somehow!