how can i convert an int type into a long type value?
Take a look at this code:
int yourInt=5;
long yourLong=(long) yourInt;
println(yourLong);
You can generally convert all number types into each other that way.
I hope this helps!
1 Like
thanks a lot, that did in fact work.
No problem! A thing to keep in mind is that when converting from a float/double to a int/long all digits after the comma will be cut!
1 Like
Java automatically upgrades an integer value to long
type by simpling assigning it to a long
variable:
int myInt = 10;
long myLong = myInt;
println(myInt, myLong); // 10, 10
exit();
However, when using literals that exceed 2 ^ 31
we have to suffix them w/ L
or l
:
//long wrongLong = 4_000_000_000;
long correctLong = 4_000_000_000L;
println(correctLong); // 4000000000
exit();
1 Like