Note that there are some explanatory texts on larger screens.

plurals
  1. POLocalizing a text field containing a number in Ruby on Rails
    text
    copied!<p>I am currently working on a project to internationalize one of our ruby-on-rails web applications so that it can be used in other countries (France will be the first one in this case).</p> <p>A particular issue I haven't worked out yet is with the displaying of numeric fields. When displaying numbers for display purposes only, I do the following:</p> <pre><code>&lt;%= number_to_percentage(tax.rate, :precision =&gt; 2)%&gt; </code></pre> <p>In English, this shows <strong>17.50</strong>, but in French it shows <strong>17,50</strong> (with a comma in place of the decimal point) which is as expected. The problem comes in the Edit form, when I show a text field</p> <pre><code>&lt;%= f.text_field :rate, :size =&gt; 15 %&gt; </code></pre> <p>When this renders a text box on the screen, the text box always shows <strong>17.50</strong> with a full stop rather than a comma for French. I am not sure that is correct.</p> <p>When I tried doing the following:</p> <pre><code>&lt;%= f.text_field :rate, :size =&gt; 15, :value =&gt; number_with_precision(f.object.rate, :precision =&gt; 2) %&gt; </code></pre> <p>This did indeed show <strong>17,50</strong> in the text box for French, but when I click on the Update button to save the form, the Ruby validation kicks in and tells me that <strong>17,50</strong> is not a number (or rather it says "n'est pas un nombre"). I have to enter <strong>17.50</strong> to get it to save.</p> <p>To be honest, I am not entirely sure on the correct thing to do here. Should all countries enter numbers with full stops in text boxes, or is there a way to get Ruby-on-Rails to display commas, and validate them appropriately?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload