Search code examples
htmlfirefoxhtml-input

Input type=number : Firefox converts floating point number to integer when there are 3 digit after a point


On Firefox 34, I getting a weird behaviour on a <input type="number">.

When typing something like 11.001 (notice the point) it gets converted to 110001.

This only happens when there are 3 digits after the point.

Is there a way to prevent that behaviour ?

By the way : I noticed that behaviour on a french Windows 7.


Solution

  • Your browser is using the french locale and french uses comma as decimal separator and period for thousands.

    From the Mozilla documentation:

    Localization

    The allowed inputs for certain types depend on the locale. In some locales, 1,000.00 is a valid number, while in other locales the valid way to enter this number is 1.000,00.

    Firefox uses the following heuristics to determine the locale to validate the user's input (at least for type="number"):

    • Try the language specified by a 'lang'/'xml:lang' attribute on the element or any of its parents;

    • Try the language specified by any Content-Language HTTP header or

    • If none specified, use the browser's locale.

    If you want to change this behavior use:

    <input lang="en" type="number">