Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

text_field should show and accept translated separator on BigDecimal fields

#1584

In a lot of european countries you use a comma to separate decimals instead of a dot: when dealing with BigDecimal fields, text_field doesn't currently care about the number/format/separator specified in the yml localization file.

But even if text_field would care, this would solve just half of the problem: we need our Rails apps not just to output numbers with commas, but also to accept them as input. So maybe it's ActiveRecord setters job to accept and translate the localized separator?

IMHO the best thing would be to patch BigDecimal class so that:

  • "new" and "=" methods would accept the localized separator
  • "to_s" would output a string containing the localized separator

Actually I tried this and everything worked... until I tried to INSERT/UPDATE my database: MySQL adapter calls "to_s" on the BigDecimal object, and of course MySQL doesn't like a decimal field containing a comma! So adapters need to be patched so that they force the "en" localization before calling the "to_s" method on the BigDecimal. Another option is to add a "to_s_not_localized" method to BigDecimal class and let the adapters call this method instead.

Reported by Alessandro Zarrilli · December 16th, 2008 @ 05:15 PM

State: stale
Milestone: 3.x
Assigned to: nobody
Importance: none

Activity

  1. Ryan Bigg
    Ryan Bigg

    Are you able to submit a patch for this showing how this fails?

    April 10th, 2010 @ 08:47 AM

  2. Clemens Kofler
    Clemens Kofler

    You could use my delocalize plugin for that (http://github.com/clemens/delocalize) – alternatively use Fernando's branch until I've pulled it in. I'm not sure something like this should go into Rails directly since it is a very complex topic.

    April 10th, 2010 @ 08:22 PM

  3. Rohit Arondekar
    Rohit Arondekar

    I agree with Clemens. This logic should be put in a plugin and not integrated into rails.

    April 11th, 2010 @ 02:05 AM

  4. Jeremy Kemper
    Jeremy Kemper
    • Milestone changed from 2.x to 3.x

    May 4th, 2010 @ 06:48 PM

  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Importance changed from to

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 05:03 PM

  6. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 05:03 PM