changhuixu / ngx-digit-only

An Angular directive to only allow [0-9] in the input box when typing, pasting or drag/dropping.

Home Page:https://changhuixu.github.io/ngx-digit-only/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Big numbers in scientific format

LemaireJean-Baptiste opened this issue · comments

Hello,

I was playing with the input and typing huge numbers. Above 16 digits there are strange behaviours happening.
Between 16 and 20 digits, numbers are rounding themselves to the nearest even number (for the 17th digit) and then whatever the digit inputed, it will only add zeros.

And for more than 21 digits, the number is converted to scientific format, which is a surprising behaviour when you are typing a number (but copied/pasted number are not converted). For even larger numbers, it is rounded to Infinity and then NaN.

Maybe instead of NaN and Infinity which can cause some issue in the algorithms filled with the input data, we can add an new condition in the onKeyDown method of the directive, to block, by default, too large number (number that can't be handle by javascript). I know that I can use a max parameters on my input, but I am wondering whether it should be a default behaviour.
And we should also prevent any conversion to scientific format.

I guess you are using input type="number". This library is intended to accept a string.
If you change the input element to input type="text", and don't convert the string to number in JavaScript, then it should work.

Oh nice thank you for your feedback. I didn't notice this point.