This project is archived and is in readonly mode.

#1584 ✓stale
Alessandro Zarrilli

text_field should show and accept translated separator on BigDecimal fields

Reported by Alessandro Zarrilli | December 16th, 2008 @ 05:15 PM | in 3.x

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.

Comments and changes to this ticket

  • Ryan Bigg

    Ryan Bigg April 10th, 2010 @ 08:47 AM

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

  • Clemens Kofler

    Clemens Kofler April 10th, 2010 @ 08:22 PM

    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.

  • Rohit Arondekar

    Rohit Arondekar April 11th, 2010 @ 02:05 AM

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

  • Jeremy Kemper

    Jeremy Kemper May 4th, 2010 @ 06:48 PM

    • Milestone changed from 2.x to 3.x
  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 05:03 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 05:03 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages