What does division by 1e9d mean?
Asked Answered
F

2

12

This is the snippet:

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

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

Flam answered 12/12, 2013 at 16:3 Comment(3)
10^9 as a double (kind of redundant).Incommutable
It's in nano second, so you'll have 1 000 000 000 ns every 1 second. If you want to display the time in plain seconds, you'll have to divide it by 10e9Placard
1e9d is scientific notationIntoxicated
I
10

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.

Inkster answered 12/12, 2013 at 16:5 Comment(2)
How will I express 1.0e-3 on the same lines? '1e-3d'? It doesn't give me any error.Flam
@Flam Or simply 1e-3Inkster
E
2

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.

Ethmoid answered 12/12, 2013 at 16:9 Comment(1)
You should perhaps add that the notation 10e9 is already enough to establis that it is a double, at least in Java. Hence the d suffix is really superfluous here.Trappings

© 2022 - 2024 — McMap. All rights reserved.