Ciao io mi sono creato questo metodo:
basta passargli il tuo valore, il carattere di riempimento che vuoi e la lunghezza che vuoi ottenere.
nel tuo caso sarebbe:
String stringa = riempiCampo(bigdecimal.toString,"0",5);
codice:
public static String riempiCampo(String valore, String riempimento, int lunghezza){
String campo = "";
if(valore==null){
campo = "";
}else{
campo = valore.trim();
}
if(campo.trim().length()<=lunghezza){
int vuoti = lunghezza - campo.length();
for(int k=0;k<vuoti;k++){
if(riempimento.equalsIgnoreCase("0")){
campo = riempimento + campo;
}else{
campo = campo + riempimento;
}
}
return campo;
}else{
if(riempimento.equalsIgnoreCase("0")){
return valore.substring(valore.length()-lunghezza,valore.length());
}else{
return valore.substring(0,lunghezza);
}
}
}
Spero ti possa andare bene... CIAO