I18nFloat is a Ruby gem to use with Rails. I18nFloat allows your users to use format number like “1 200,84” in forms. ActiveRecord Float attributes don’t care anymore if you like commas or dots!.

With this gem loaded, your users are able to use comma style decimal in forms.

Features

Here are current features but ideas and contributions are welcome:

  • comma for decimals
  • whitespace as separator
  • standard format still usable
  • only a gem in your Gemfile and you’re good to go

Installation

$ gem install I18nFloat

Usage

Let’s say you’ve got a Marathon model with a Float columns named duration:

Marathon.new(:duration => "9300303.92")
# => #<Marathon id: nil, duration: 9300303.92, created_at: nil, updated_at: nil>
Marathon.new(:duration => "9300303,92")
# => #<Marathon id: nil, duration: 9300303.92, created_at: nil, updated_at: nil>
Marathon.new(:duration => "9 300 303,92")
# => #<Marathon id: nil, duration: 9300303.92, created_at: nil, updated_at: nil>

Other

If you want to contribute you should take a look at:

Source can be cloned using Mercurial on my Bitbucket repo.

Problems, comments, and suggestions are welcome on the tracker.

This gem is released under the MIT license.

Have comments or want to discuss this topic?

Send an email to ~bounga/public-inbox@lists.sr.ht