2012-03-13 7 views

答えて

4

使用number_with_delimiter(12000, :delimiter => ' ')

2

number = 12000 
number_to_currency(number, :precision => 0, :unit => "", :delimiter => number.to_s.length > 4 ? " " : "") # 12 000 

number = 5000 
number_to_currency(number, :precision => 0, :unit => "", :delimiter => number.to_s.length > 4 ? " " : "") # 5000 

number = 1000000 
number_to_currency(number, :precision => 0, :unit => "", :delimiter => number.to_s.length > 4 ? " " : "") # 1 000 000 

number = 20000000 
number_to_currency(number, :precision => 0, :unit => "", :delimiter => number.to_s.length > 4 ? " " : "") # 20 000 000 

質問の要件が変更された後:純粋なRubyで

number_to_currency(number, :precision => 0, :unit => "", :delimiter => " ") 
2

を:

"20000000".reverse.chars.each_slice(3).map(&:join).join(' ').reverse 

だから、すべての手段によって、ヘルパーメソッドを使用します。

+0

ヘルパー向けです。どうも – bravedick

関連する問題