Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

converting double into integer

 
Siti Nurlela Kamarudin
Greenhorn
Posts: 1
  • 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: 24211
35
Chrome Eclipse IDE Mac OS X
  • 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