12000 = 12 000
5000 = 5 000
1000000 = 1 000 000
20000000 = 20 000 000
沒有JavaScript :)
12000 = 12 000
5000 = 5 000
1000000 = 1 000 000
20000000 = 20 000 000
沒有JavaScript :)
使用number_with_delimiter(12000, :delimiter => ' ')
你好這就是你正在尋找:
http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.html
像 - number_to_currency(1234567890.506, :locale =>:fr)#=> 1 234 567 890,51€
希望這有助於,歡呼!
之前問題的要求發生了變化:
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
問題的要求之後已經改變:
number_to_currency(number, :precision => 0, :unit => "", :delimiter => " ")
在純Ruby:
"20000000".reverse.chars.each_slice(3).map(&:join).join(' ').reverse
因此,通過各種手段使用一個輔助方法。
好幫手。謝謝 – bravedick 2012-03-13 09:19:09