Forum: Ruby on Rails Decimal comma instead of decimal point (i18n issue)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
8a8ba7e85e336beb1304453ef20a7470?d=identicon&s=25 Karel Miarka (kajism)
on 2006-02-23 15:24
Hello,

What is the easiest way which enables usage of decimal comma "," instead
of decimal point (".") . I would like to force all RoR views to display
float numbers with comma instead of decimal point and also to allow
insertion of float numbers with comma in forms.

Thanks in advance,
Karel
F734b6ca0eb2ebd01744224437a72498?d=identicon&s=25 Harm de Laat (Guest)
on 2006-02-23 20:14
(Received via mailing list)
I would like to know this too... I'm watching this thread!
Ef5ab33bba8dd9ca281e42c7a1642113?d=identicon&s=25 Gabriel Birke (archangel77)
on 2006-02-24 01:05
Karel Miarka wrote:

> What is the easiest way which enables usage of decimal comma "," instead
> of decimal point (".") . I would like to force all RoR views to display
> float numbers with comma instead of decimal point and also to allow
> insertion of float numbers with comma in forms.

Have you looked at Globalize?
http://globalize-rails.org/wiki/

I haven't tested it yet, but it seems that it will be a good and mature
I18N solution someday.
D444791fa932ffdb231ff35458e1d1fa?d=identicon&s=25 Joshua Harvey (joshmh)
on 2006-02-24 04:29
If you just want to force all numbers to have decimal commas and you
don't have to switch between different languages or locales, Globalize
might be overkill.

You can just use the number_to_currency helper method:

number_to_currency(1234567890.50, {:unit => '', :separator => ',',
:delimiter => '', :precision => 2}) -> 1234567890,50

or

number_to_currency(1234567890.50, {:unit => '', :separator => ',',
:delimiter => '.', :precision => 2}) -> 1.234.567.890,50

If you use this, you'll probably want to define your own helper method
in app/helpers/application_helper.rb:

def format_number(num)
  number_to_currency(num, {:unit => '', :separator => ',', :delimiter =>
'.', :precision => 2})
end

Josh
http://shnoo.gr

Gabriel Birke wrote:
> Karel Miarka wrote:
>
>> What is the easiest way which enables usage of decimal comma "," instead
>> of decimal point (".") . I would like to force all RoR views to display
>> float numbers with comma instead of decimal point and also to allow
>> insertion of float numbers with comma in forms.
>
> Have you looked at Globalize?
> http://globalize-rails.org/wiki/
>
> I haven't tested it yet, but it seems that it will be a good and mature
> I18N solution someday.
This topic is locked and can not be replied to.