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.

Share:
14,482
farissyariati
Author by

farissyariati

A novice programmer. Interested in Java and Android Programming.

Updated on June 04, 2022

Comments

  • farissyariati
    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
    David Heffernan over 11 years
    It would probably be easier to avoid using any floating point at all and avoid the conversion
  • arshajii
    arshajii over 11 years
    Ints can hold up to 2147483647.
  • arshajii
    arshajii over 11 years
    Well 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
    David Heffernan over 11 years
    What you have, and what OP has, is a literal. In which case, make it an int literal.
  • arshajii
    arshajii over 11 years
    @SteveKuo Try the following: System.out.println((1e2 + 1) / 2) and System.out.println((100 + 1) / 2). The first prints 50.5 (regular division) and the second prints 50 (integer division) - showing that 1e2 is not an integer (in the Java-sense) but rather a double. Same can be said for 2e+08.