-2

Want to assign 12 digits number in a long type variable error: integer number too large: 100000000000 long no = 100000000000;

long no = 100000000000;

2 Answers2

1

You need to treat the literal as a long as well using "L" at the end of the number:

long no = 100000000000L;

Without the literal, the number is treated as an int.

Oleksi
  • 12,947
  • 4
  • 56
  • 80
  • what should I do when I am converting string number in Long int ex: long accountNoEntered = Integer.parseInt(accountNoT.getText()); I am taking a string from JTextField – Sumit Kawale Mar 08 '20 at 19:34
  • 1
    @SumitKawale you can use `Long.parseLong(String s)` – Oleksi Mar 08 '20 at 19:44
1

This is because by default every constant number you're assigning to a variable is seen as an int. To make your example work, you need to add an "L" at the end of the number.

long no = 10000...L;
user1234SI.
  • 1,812
  • 1
  • 8
  • 22