I am parsing a 15-digit string as follows:
String str = "100004159312045"; int i = Integer.parseInt(str);
I get an exception when doing this. What for? What are the limitations for Integer.parseInt ? What other options are there for converting such a long string to a number?
Integer.parseInt
Your number is too big to match an int , which is 32 bits and only has a range from -2,147,483,648 to 2,147,483,647.
int
Try Long.parseLong . A long has 64 bits and has a range from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Long.parseLong
long
int - 32-bit bit, its maximum value is 2 ^ 31-1 = 2147483647
because int maximum value is slightly over 2,000,000,000
you can use long or BigInteger
long has a double digit that it can store (the maximum value is square than the value of int), and BigInteger can handle arbitrarily large numbers
The value you are trying to analyze exceeds the maximum size of Integer.
The range int is between Integer.MAX_VALUE and Integer.MIN_VALUE inclusive (i.e. from 2147483647 to -2147483648). You cannot parse the int value of this range.
Integer.MAX_VALUE
Integer.MIN_VALUE
You can use long m = Long.parseLong(str); or BigInteger b = new BigInteger(str); for a big whole.
long m = Long.parseLong(str);
BigInteger b = new BigInteger(str);
Source: https://habr.com/ru/post/900901/More articles:Access errors in the Symfony2 controller for the submitted AJAX form - phpHow to combine two separate but identical codes into one SVN frame? - genericsUse PHP to split an image into pixel divs - javascriptnode.js + express.js + socket.io authorization: no cookies - node.jsHow to pass a variable as key $ _POST in PHP? - variablesVariadic list constructor, how to use the correct type by default and get the security type - type-safetyWhy does CMP (comparison) sometimes set the Carry flag in assembly 8086? - assemblyWhat C ++ feature allows template classes to refer to themselves without template arguments? - c ++Variadic arguments using Type Families instead of Multi-param Typeclasses - haskellRails 3.1: Sass Import from Lib - ruby-on-railsAll Articles