Well, you can calculate the amount based on the length of the non-decimal number:
public String doubleToString(double in) {
int length = (((int) in) + "").length(); //non-decimal length
if (length <= 0 || length > 10) {
//error out? not sure how you wish to handle 11-digit numbers
}
return String.format("%." + (10 - length) + "f", in); //format decimal
}
Shortened:
//default to 0 decimals for >10 digits
public String doubleToString(double in) {
return String.format("%." + Math.max(0, (10 - (((int) in) + "").length()) + "f", in);
}