Double keeps rounding to integer?

I'm working with an audiostream, using the clip.getMicrosecondPosition() method to find out how many microseconds have passed.

When left alone, the microsecond value is dead on precise - but when I try to multiply it and convert to to a decimal (double), it always rounds to the nearest integer.

Here's the code: Code:

`double seconds = clip.getMicrosecondPosition() / 1000000;`

The integer number it rounds to is correct for how many seconds have passed, but I need the double to show the tenth-second as well. For instance, when 1000000 microseconds have passed, it will show the double as 1.0, but when 1324752 have passed, it still shows 1.0 rather than 1.3. I've tried a few decimal formatting and double parsing tricks and everything else I could find/think of, but so far nothing is working.

Help would be much appreciated!

Re: Double keeps rounding to integer?

The expression to the right of the = is all int values so int rules are used. Change the divisor to double by adding a .0D to the end to get a floating point value.

Re: Double keeps rounding to integer?

Cheers! :(handshake):

Here's the final code:

Code:

`seconds = clip.getMicrosecondPosition() / 1000000.0D;`

seconds = (double) Math.round(seconds * 10) / 10;