EDIT : THE TITLE IS MISLEADING since after some testing it turns out that Number()
returned a dot-separated number and it was the HTML <input type="number"/>
which visualized it as comma due to locale settings.
I then resorted to use a <input type="text"/>
and filter keydown just like the jQuery version of this answer: html-text-input-allow-only-numeric-input.
ORIGINAL QUESTION:
I need to put a number from javascript into an <input type="number"/>
html tag using AngularJS ng-model
.
I've got a number-like string with .
as decimal separator, and putting directly the string into the input obviously gives me an error ( numfmt ).
Problem is, I need the number to be dot-separated but both Number()
and parseFloat()
only return a comma-separated number (rightly so, according to italian locale).
How can I retain the dot-separation without having to revert to <input type="text"/>
? I need the automatic input-control on the type="number"
and I don't want to use libraries for just this little thing.
I feel like this ought to be a key feature in js but for the life of me I can't find anything on the web.