Hello guys! I want you to help me with something. I need to use the pow() method which can only be used with double data type. But I also need to use the result in a mod operation (%) which is only defined for int data type. So there must be a way to convert doubles to integers. Do you know how? thanks

12-11-2007, 12:27 AM

dmacvittie

Hello Alejandro,

Try looking at Double.intValue() and Integer.doubleValue(). They should give you what you're looking for.

Don.

12-11-2007, 02:34 AM

staykovmarin

Or you could always cast (although that is not as safe, since it can fail)

Code:

double d = 7.8;
int i = (int) d;

note: that wont round. it will give you 7, although it should give you 8 (since we round up).