3E5 in Java for Android

3E5 in Java for Android

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 ^

4

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor
Author

Sophia Al-Mansoor

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.