简体   繁体   中英

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 ^

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM