Use
double number = getNom() / (double)getDenom();
how to make a method return a double [duplicate]
-
03-10-2022 - |
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;
Solution
OTHER TIPS
One alternative is use double number = getNom() * 1.0 / getDenom();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow