3

With angular input numbers, I notice that if I enter large numbers they can get rounded to something different.

For example, in this plunkr http://plnkr.co/edit/k5G7eL8gIzWbSPGocdlQ?p=preview I set a large max number like this:

<input type="number" name="input" ng-model="value" min="0" max="9223372036854769" required>

Then, if I enter 9223372036854769 in the input field it gets rounded down one. If I enter 9223372036854767 it gets rounded up one.

Considering only integer numbers (no decimals), what is the maximum integer value inputs can receive without rounding? And what is the minimum?

user3141592
  • 1,069
  • 2
  • 10
  • 20

2 Answers2

5

The value 9223372036854769 is more than Number.MAX_SAFE_INTEGER. A good explanation on your problem can be found in http://www.2ality.com/2013/10/safe-integers.html

Deepak N
  • 2,561
  • 2
  • 30
  • 44
3

It is not related to angular but more so to JavaScript in which numbers have precision up to 2^53 both positive and negative.

ECMA number spec

neo112
  • 1,703
  • 2
  • 17
  • 39
  • Thanks. I now see this in http://stackoverflow.com/questions/307179/what-is-javascripts-max-int-whats-the-highest-integer-value-a-number-can-go-t. Before I posted the question, I looked up the max javascript number which was clearly larger than this. But I didn't know about precision limits and I assumed it must be an angular or a html input issue. – user3141592 Sep 18 '14 at 17:31
  • Interestingly, the spec you pointed me to has an error. In the first sentence on page 30 they meant the number (2^31)−1. But the document formatter raised the "-1" as a superscription so it looks like 2^(31-1). – user3141592 Sep 18 '14 at 17:36