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;
Était-ce utile?

La solution

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

Autres conseils

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top