This might be a very simple questions but i cant find a hint anywhere.
I have check the below links but still cannot find what is wrong with my code.
Returning a double from a method
Easiest way to return double from another class
What i want is to return a method that return a 2 decimal double.
Call the below method but it is not running.
toDouble(double1);//the result are not 2 decimals
edittext.setText(String.valueOf(double1));
public double toDouble(double d){
String str = String.format("%1.2f", d);
d = Double.valueOf(str);
return d;
}
It work well when i code like this
String str = String.format("%1.2f", double1);
double1 = Double.valueOf(str);
Anyone can guide me in this?
Edit 1
If anyone reading this. It is a silly mistake.
**Forgot to define the double
double1 = toDouble(double1);//the result are not 2 decimals
edittext.setText(String.valueOf(double1));