Question

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;
Was it helpful?

Solution

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

OTHER TIPS

One alternative is use double number = getNom() * 1.0 / getDenom();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top