javamethodstostringrational-numbers

how to make a method return a double


i have the following code and getNom and getdenom are both integers for example 2 and 5. How come I am getting the output of 0.0 here and not 0.4? Thank you.

public double divide() {
        double number = getNom() / getDenom();
        rn.toString(number);
        return number;

Solution

  • Use double number = getNom() / (double)getDenom();