aspose 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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 24168
    
  30

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
 
Similar Threads
immutable class?
need to use scrollbar in java
I need to put a double into a vector
How to get JScrollPane to go to top left??
Integer to double