# Thread: Double keeps rounding to integer?

1. Member
Join Date
May 2012
Posts
15
Rep Power
0

## 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:
Java 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!

2. ## 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.

3. Member
Join Date
May 2012
Posts
15
Rep Power
0

## Re: Double keeps rounding to integer?

Cheers!

Here's the final code:

Java Code:
seconds = clip.getMicrosecondPosition() / 1000000.0D;
seconds = (double) Math.round(seconds * 10) / 10;

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•