This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting double into integer

 
Siti Nurlela Kamarudin
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic