Convert 2e+08 to integer in Java
14,482
2e+08
means 2 multiplied by 10^8. In other words, 2 followed by 8 zeros:
2e+08 = 200000000
To convert it to an int
we can simply cast:
int n = (int)2e+08
All of the following are equivalent in Java: 2e+08
, 2e08
, 2e8
, 2E+08
, 2E08
, 2E8
.
Author by
farissyariati
A novice programmer. Interested in Java and Android Programming.
Updated on June 04, 2022Comments
-
farissyariati almost 2 years
I'd like to know what the
2e+08
format in programming means? I have some data related to project budget. How to convert it into integer in Java ? -
David Heffernan over 11 yearsIt would probably be easier to avoid using any floating point at all and avoid the conversion
-
arshajii over 11 yearsInts can hold up to 2147483647.
-
arshajii over 11 yearsWell we don't know where the OP gets this value, maybe it is returned by some function in some library that uses floating-point.
-
David Heffernan over 11 yearsWhat you have, and what OP has, is a literal. In which case, make it an
int
literal. -
arshajii over 11 years@SteveKuo Try the following:
System.out.println((1e2 + 1) / 2)
andSystem.out.println((100 + 1) / 2)
. The first prints50.5
(regular division) and the second prints50
(integer division) - showing that1e2
is not an integer (in the Java-sense) but rather a double. Same can be said for2e+08
.