# Convert microseconds to seconds

• 12-30-2009, 01:21 PM
Basit56
Convert microseconds to seconds
Hi,
Hope you all will be fine.I know it's a very basic question but i don't know why i am unable to doing it. Anyways i want to find a length of a .wav file, for this, i use this code but it returns length in microseconds

Code:

` System.out.println( clip.getMicrosecondLength() );`
and the output is

5875000

i want this to be in seconds means if i convert this to seconds it becomes 5.875 sec, so i want that when i execute this line it gives me only 6 sec after rounding of or 5 or 20 sec only, means only int value no decimal value.

I also tried this
Code:

`System.out.println( clip.getMicrosecondLength()/0.000001 );`
and also

Code:

`System.out.println( (clip.getMicrosecondLength()/0.000001)%60 );`

Thank you
• 12-30-2009, 01:24 PM
r035198x
Read the API specs for the Math.round method.
• 12-30-2009, 01:25 PM
Fubarable
Edit: Please ignore this brain fart. Sorry!
• 12-30-2009, 01:30 PM
r035198x
Quote:

Originally Posted by Fubarable
Maybe my math is off, but my brain tells me that

5875000 ms / 1000 = 5875 seconds

There is a millisecond vs microsecond thing going on there.
• 12-31-2009, 06:54 AM
Basit56
Hi,
Thank you to all for your help. Really it's very simple. Simply

Code:

``` /**         * Conversion in seconds. Since         * 1 microsecond = 10^(-6) sec         * 1 microsecond = 1/1000000 sec         */         System.out.println("seconds: " + (clip.getMicrosecondLength()/1000000) );```
Thank you