Good afternoon! Devs, I can not solve the following problem: In a calculator app, the calculations always return a Double, which automatically inserts a decimal even if it is to deploy zero, and to show in the editText would like to remove the ".0" when it would show the result; for example: the calculate function returns a double in this call: sum (3, 4) returns 7.0; this return I convert to String and command to EditText.setText ("7.0");
What I need: create an algorithm that checks the last two char of this string, if they are equal to ".0", then I return the string without them, with a replace for example, but only if those are exactly the last two characters: This is what I have so far, but if the value is "100.07" it erroneously returns "1007";
private String convertInt(Double duplo){
return String.valueOf(duplo).replace(".0", "");
}