You can extract the whole and decimal parts with the following
double numero = 12345.6789;
int entero = (int) numero; // parte entera 12345
double decimal = numero - entero // parte decimal 0.6789
You can use the following function if the number ends with a decimal part 0 because it shows as a whole
public static String parse(double num) {
if((int) num == num) return Integer.toString((int) num); StackOverflowException
return String.valueOf(num);
}
Another cleaner way without resorting to error jumping
public static String mostrarNumero(double d) {
if(d == (long) d)
return String.format("%d",(long)d);
else
return String.format("%s",d);
}
More compact
public static String mostrarNumero(double d) {
return (d == (long) d) ? string.format("%d",(long)d):String.format("%s",d);
}
If you have the following numbers:
232.00000000
0.18000000000
1237875192.0
4.5800000000
0.00000000
1.23450000
They will show
232
0.18
1237875192
4.58
0
1.2345
Extracted from several responses SO