Using Math.floor

When I use Math.floor I get an integer part of a double rigth?

For exemple >> If I have

double num = 34.54

Math.floor(num) will return 34 rigth?

But this 34 is a double 34.0 or is an integer 34?

If not an integer, how can I do to get the integer part "34" like a integer number 34 and not like a double 34.0?

[353 byte] By [coelholdsa] at [2007-11-26 22:42:38]
# 1
int i = (int) double
TuringPesta at 2007-7-10 11:58:17 > top of Java-index,Java Essentials,New To Java...
# 2
I used but NetBeans says inconvertible types
coelholdsa at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 3
NetBeans saysinconvertible typesfound: java.lang.Doublerequired: int
coelholdsa at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 4
read reply 2. you need to cast it like turingpest showed you.
lrngjavaa at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 5

Yes I already did it but it is not working

Here is the code

private void confirm(Double list[]){

int nParcelas = (int)(list[2]);

.....

I call the function confirm from another class, and I pass a list like parameter.

I have the same fuction but is a list of String and work ok. I get the numbers of this list and make some operations and averything works find...

But I want to get an item of this list and get its integer part, and it it's not working....

coelholdsa at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 6
a Double is not a double you bobo : )
TuringPesta at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 7
FYI: "Double" is not the same as a "double". You need to convert your Double to a double before casting it to an int.
ignignokt84a at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 8
Here is the answer:private void confirm(Double list[]){int i = list[2].intValue(); http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Double.html
TuringPesta at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 9
> You need to convert your Double to a double before> casting it to an int.not exactly. Double has an intValue() method.
TuringPesta at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 10

> > You need to convert your Double to a double before

> > casting it to an int.

>

> not exactly. Double has an intValue() method.

Oops, I thought it did, I even checked the API before posting. Must have missed it though. I even thought to myself "Kinda stupid Double doesn't have an 'intValue()' method...". : )

ignignokt84a at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 11
rsrsrs .....:( rsrsthank you very muchnow it is workingSo let me see if I understood....Double is a class witch have a lot of methods, etcdouble is the type of a nunber but it is not a classAm I right?
coelholdsa at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 12

> rsrsrs .....:( rsrs

>

> thank you very much

>

> now it is working

>

> So let me see if I understood....

>

> Double is a class witch have a lot of methods, etc

Yes. It is called a wrapper class. Just like java.lang.Integer (wrapper for an int), java.lang.Boolean (wrapper for a boolean), ...

> double is the type of a nunber but it is not a class

>

> Am I right?

Correct. Those are called primitives:

http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

prometheuzza at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 13
double = a primitiveDouble = an ObjectDouble is just a wrapper for double when you need an Object.Under normal circumstances you should use double and not Double.double will be faster (thats why Java has primitives to begin with).
TuringPesta at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...
# 14
Ok now I see, thank you, thank you
coelholdsa at 2007-7-10 11:58:18 > top of Java-index,Java Essentials,New To Java...