Closed
Bug 1161006
Opened 11 years ago
Closed 10 years ago
<input type=number> sometimes loses precision for numbers with large numbers of significant digits
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: alvindsdelacruz, Unassigned)
Details
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0
Build ID: 20150415140819
Steps to reproduce:
used input type number with min=8901260000000000000 and max=8901260999999999999
Actual results:
tried typing in 8901260962115482165 but returns 8.90126096211548e+18
Expected results:
value must not be rounded off
Updated•11 years ago
|
Group: core-security
Component: Untriaged → HTML: Form Submission
Product: Firefox → Core
Comment 1•11 years ago
|
||
http://www.w3.org/TR/html5/forms.html#number-state-%28type=number%29
http://www.w3.org/TR/html5/infrastructure.html#valid-floating-point-number
Your values exceed the maximum 53-bits that can safely be represented as an integer in a IEEE 754 double-precision floating-point. Max value before rounding is 9007199254740991. This is expected behavior.
See also:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago
Resolution: --- → INVALID
Hi Dave,
If this is true that my values exceed the MAX_SAFE_INTEGER, then why does the following figures behave differently:
1. 8901260962115482112 - Firefox passes the value as is
2. 8901260962115482113 - This is where the rounding off starts
3. 8901260962115482199 - This is the last value that rounds off
4. 8901260962115482200 - Firefox passes the value as is again
Also, is this global? Because it works in Google Chrome.
Thanks,
Alvin
Status: RESOLVED → UNCONFIRMED
Resolution: INVALID → ---
Comment 3•10 years ago
|
||
"max safe" means the maximum you can reliably expect to get, not the maximum you will always get.
Updated•10 years ago
|
Status: UNCONFIRMED → RESOLVED
Closed: 11 years ago → 10 years ago
Resolution: --- → DUPLICATE
Updated•10 years ago
|
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: DUPLICATE → ---
Comment 5•10 years ago
|
||
(In reply to Al from comment #2)
> If this is true that my values exceed the MAX_SAFE_INTEGER, then why does
> the following figures behave differently:
>
> 1. 8901260962115482112 - Firefox passes the value as is
> 2. 8901260962115482113 - This is where the rounding off starts
> 3. 8901260962115482199 - This is the last value that rounds off
> 4. 8901260962115482200 - Firefox passes the value as is again
Note the difference between input.value and input.valueAsNumber. When you set these values as the value of the 'value' attribute Firefox will try to preserve the string in input.value, but input.valueAsNumber will almost always be a different number. It will only be the same if the binary representation of the number happens to only require 53 significant binary digits because any additional binary digits that might be required would happen to be zeros.
> Also, is this global? Because it works in Google Chrome.
Chrome also tries to preserve any string assigned to the 'value' attribute in the 'value' property, and does a better job that Firefox in this regard (see bug 1005603).
Note also bug 1095539 which may be of interest to you.
Status: REOPENED → RESOLVED
Closed: 10 years ago → 10 years ago
Resolution: --- → INVALID
Updated•10 years ago
|
Component: HTML: Form Submission → DOM
Summary: Rounding off input type number → <input type=number> sometimes loses precision for numbers with large numbers of significant digits
| Assignee | ||
Updated•7 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•