| Author |
any one know how to change a long to an int?
|
Andrew Brown
Greenhorn
Joined: Apr 10, 2006
Posts: 25
|
|
having problems changing a long from a System.currentTimeMillis(); in to an integer. (It smaller than the time as it's the difference between two times so no worries on the size restrictions) Cheers
|
Thanks for any help anyone can offer.
|
 |
Ankur Sharma
Ranch Hand
Joined: Dec 27, 2005
Posts: 1234
|
|
I don't understand why you want to convert this one because definately System.currentTimeInMillis will gave a large number which might be not comfortably suited in int.. That will might be loose the data you really want.... otherwise still if you want to convert the long into Int the Altenative way is:: This is how a long can be converted to int variable... But still it will be better if you eloborate your question some more... so that ranchers will guide you the alternative way......
|
 |
Jass Singh
Ranch Hand
Joined: Mar 30, 2006
Posts: 52
|
|
Ankur: Andrew has already told that value is a difference between times and hence a small value-
Originally posted by Andrew Brown: (It smaller than the time as it's the difference between two times so no worries on the size restrictions) Cheers
Andrew: Approach shown by Ankur is perfectly fine. Regards, Jass
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
Originally posted by Jass Singh: Ankur: Andrew has already told that value is a difference between times and hence a small value
Just a quick point. It is essential that you do the subtraction of the times using longs, then cast the difference to int. If you cast the two times to int then subtract them, all sorts of intermittent problems would occur.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Andrew Brown
Greenhorn
Joined: Apr 10, 2006
Posts: 25
|
|
thank you for your help, it worked a treat!
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
I have tried it out and got some errors. I think, if the difference is less than Integer.MAX_VALUE, you will get the correct answer, but if the difference is more than Integer.MAX_VALUE, you will get overflow problems. Casting the values to (int) before the subtraction doesn't seem to make any difference. CR
|
 |
 |
|
|
subject: any one know how to change a long to an int?
|
|
|