Search code examples
javacastingdoublegreenfoot

Greenfoot: Converting a double into an intenger; int cannot be dereferenced


I want to turn any double value into an intenger. I know that the part behind the comma will be lost.

import java.lang.*;

public int doubleToIntenger(double dbl){
    int intenger;
    intenger = intenger.intValue(dbl);
    return intenger;
}

But I'm getting this error as a tooltip in my editor:

int cannot be dereferenced

Solution

  • Just cast double to int, if you only care about before fraction.
    But be carefull

    double x = 1.999999;
    int val = (int)x;// val will be 1