my dog learned polymorphism*
The moose likes Beginning Java and the fly likes intValue( ) doesn't work... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "intValue( ) doesn Watch "intValue( ) doesn New topic
Author

intValue( ) doesn't work...

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
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

Joined: Jan 03, 2006
Posts: 490
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 ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
I was just trying way to hard, lol. Thanks much!
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
You are welcome

I think we have all been there, some of us a lot more then once.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: intValue( ) doesn't work...
 
Similar Threads
postfix and prefix increment precedence in conditional expressions
converting a double to an int
location of isNumeric() ??
Converting a Double to an Int
Big Problem with decimalFormat