Railsで金額表示(日本)の実装
忘れそうなので、メモしておきます。
必要なgemをインストール
# gem sourcesに登録されていなかったら $ gem so -a http://gems.github.com # gemをインストール $ gem i amatsuda-i18n_generators # 日本語のリソースファイルを生成 $ script/generate i18n ja
Viewの実装
number_to_currencyメソッドで日本語の金額表示にフォーマットしてくれます。
<%=h number_to_currency(12345) %> =>12,345円
2011/04/02 追記 Rails3の場合
$ rails plugin install git://github.com/amatsuda/i18n_generators.git $ rails g i18n ja
app/helpers/application_helper.rb
module ApplicationHelper include ActionView::Helpers::NumberHelper # ここ追加 :
config/locales/ja.yml
currency: format: format: "%n%u" unit: "円" separator: "." delimiter: "," precision: 0 # 3から0に変更 significant: false strip_insignificant_zeros: false