jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes converting double into integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "converting double into integer" Watch "converting double into integer" New topic

converting double into integer

Siti Nurlela Kamarudin

Joined: Jul 19, 2003
Posts: 1
Hi, need some help here. i have to convert a double into integer and use it to set my JScrollBar. Since JScrollBar dosen't take a double i've use this method
and this is the error
double cannot be dereferenced
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

You can't call methods on primitive types like double, or int, float, long, short, byte, char, or boolean. You might be confusing double with java.lang.Double, which is a a class which does indeed have an intValue() method. But a double is not a Double.
Anyway, if you have a value of type double and you need a value of type int, you can use a cast:

Note that fractions will be truncated towards zero; if your double is between 0 and 1, then casting it to an int will give you 0.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link: http://aspose.com/file-tools
subject: converting double into integer
It's not a secret anymore!