I work in javascript but I'm participating in a project for android. I'm trying to write great numbers. In JS I'd write, for example 3e5 to get 300000. Is it the same in Java, I searched but I couldn't get an answer not using pow ^
1 Answer
In JS I'd write, for example 3e5 to get 300000
In java is almost (*) the same:
double x = 3e5;
float y = 3e5f;
This is for floating-point numbers, here is the complete spec for floating-point literals: JSL-3.10.2
For integers this is not supported in java. You can force a narrowing primitive conversion, but keep in mind you might lose precision:
int n = (int) 3e5;
(*) Footnote: I don't know JS, but it looks the same to me in this example.