Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does division by 1e9d mean?

This is the snippet:

String myTime = someTime / 1e9d + ",";

someTime is derived by using System.nanoTime(). What does 1e9d do here?

like image 968
user1071840 Avatar asked Dec 12 '13 16:12

user1071840


People also ask

What does 1e9 mean in Java?

1e9 simply means (1) * (10^9) Typecast 1e9 to int since by default is is double => (int)1e9.

What does E10 mean in Java?

E10 means move the decimal to the right 10 places.

What is 1e9 in C++?

The e (or E ) means "times 10-to-the", so 1e9 is "one times ten to the ninth power", and 1e-9 means "one times ten to the negative ninth power".


2 Answers

1e9 means 10^9
2d means 2 as double

e.g.

  • sysout 1e9 => 1.0E9
  • sysout 10e9 => 1.0E10

See also the Floating-Point Literals section of The Java™ Tutorials.

like image 56
Georgian Avatar answered Sep 26 '22 10:09

Georgian


The suffix d denotes a double number. If the number wasn't treated as a floating point number, then the division would be considered an integer division, returning an integer (e.g. 3/2=1).

1e9 is simply 10^9. The conversion seems to be from nanoseconds to seconds.

--EDIT--

Ingo correctly points out that 10e9 is already evaluated by java to a double (see this part of the spec for details). Therefore the 'd' isn't needed in this case.

like image 27
Eyal Schneider Avatar answered Sep 26 '22 10:09

Eyal Schneider