File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

converting double into integer

Siti Nurlela Kamarudin
Greenhorn

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
ScrollBar.setValue(value.intValue())
and this is the error
double cannot be dereferenced
Help!
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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