The number type input accepts decimals without keeping the "step" atribute when number > 15 digits
Reported by
andy.c...@gmail.com,
Jan 30 2018
|
||||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
Steps to reproduce the problem:
1. make a form with the following input field:
<input type="number" value="0" id="amount" min="0.01" step="0.01">
2. Open the page in Chrome
3. Put 555555555555555.011 as input
4. Send the form
What is the expected behavior?
Chrome should show a tooltip asking to correct the field to be: 555555555555555.01 or 555555555555555.02
What went wrong?
The validation of the step condition is probably done with a data type that overflows. With 14 digits the tooltip starts to show some errors. With 15 the validation simply stops working and the form is submited.
Did this work before? N/A
Does this work in other browsers? N/A
Chrome version: 63.0.3239.132 Channel: stable
OS Version: 10.0
Flash Version:
,
Jan 30 2018
The web uses IEEE754 double-precision float format for the numbers, which can reliably represent only 15 digits [1]. The internal representation of your number in the browser is 0.555555555555555e15 As you can see, your number has 18 digits, but only 15 are actually stored. You'll have to switch to type="text" with 'pattern' attribute [2] and use a custom implementation of up/down increment buttons. Or maybe you can find/adapt an existing js library. [1]: https://en.wikipedia.org/wiki/IEEE_754 [2]: https://developer.mozilla.org/docs/Web/HTML/Element/input#attr-pattern
,
Jan 30 2018
@Reporter: Could you please provide sample URL/test file to test this issue. This would help in further triaging of the issue. Thanks!
,
Jan 30 2018
,
Jan 31 2018
Comment 2 explained the situation well. Firefox has a similar issue. We might be able to add some warning messages about precision loss on parsing input digits. However my decision is to do nothing for this issue due to small benefit. |
||||
►
Sign in to add a comment |
||||
Comment 1 by krajshree@chromium.org
, Jan 30 2018