• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

converting double into integer

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic