• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

intValue( ) doesn't work...

 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all!

I am trying to truncate a double by converting it to an integer with the intValue() method from java.lang.double. I get an error saying that it cannot find the method but from what I've researched this is supposed to work, I tried it a couple of ways. I know you can use floor to get rid of the decimal part but for the assignment I'm not supposed to do it, I'm supposed to use a method to truncate. Anyone have any ideas, maybe I'm doing something wrong?


*neither of these ways of using the method worked...

 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have a double, not a Double. What you have is the primitive value, not an object. Primitive values, are not objects and as such, have no methods available to them.

To get an integer(not Integer) cast it. (int)num;
[ March 21, 2006: Message edited by: Rusty Shackleford ]
 
Brandi Love
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just trying way to hard, lol. Thanks much!
 
Rusty Shackleford
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome

I think we have all been there, some of us a lot more then once.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic