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 ?
2 Answers
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+08All of the following are equivalent in Java: 2e+08, 2e08, 2e8, 2E+08, 2E08, 2E8.
That number uses scientific notation. The e signifies exponentiation, in this case to base 10. So this number is 2×108.
Because calculators, computer programming languages etc. typically do not use superscript notation, e is used to indicate the exponentiation.
To represent that number in Java, as an integer literal, write it like this:
200000000
As @Saintali helpfully points out, in Java SE 7 and later you can use underscores in the literal to improve clarity:
200_000_000
If the data you are reading uses scientific notation, then it represents floating point values. Should you really be converting this to integer data? If you do need to read this in from file and then convert to int, you should read into a floating point data type and then cast to int.