3

I get following exception:

java.lang.NumberFormatException: For input string: "3693019260"

while calling

Integer.parseInt(s);

And I don't know why I get it.

  • 3693019260 is smaller than 2^32
  • 3693019260 is clearly a natural number
  • the String is cleared from all non-digit elements with s.replaceAll("[^0-9]", "")

So why do I get this exception?

According to the little bit of debugging I did, I saw that the number dips under multmin but I don't know what this variable does and how I should interpret this observation.

Armin
  • 441
  • 4
  • 20

1 Answers1

5

While 3693019260 may fit into a 32 bit unsigned integer, it looks like you are trying to parse it into a plain int which is a signed integer. Signed simply means that it supports negative values using -.

With signed numbers, half of the namespace is reserved, so your number must fit into 2^32÷2−1 2147483647 instead of simply 2^32.

The simplest fix is to parse the value as a long instead of an int. Long numbers are 64 bits and support many more digits in the string.

700 Software
  • 85,281
  • 83
  • 234
  • 341