I have a report where I show certain numerical values that come to me from a service x,
My specific problem is that if the number is 5.10
the service sends me 5.1
If I send 5.00 the service brings me 5
But if I send 5.23 if I get 5.23, what I want to do is:
that if 5.1 arrives, it is completed with 5.10, if it arrives with 5, leave it as 5.00, I thought about doing this with 2 IFS and asking for the number of characters and adding the 0 but it seems inefficient or very precarious to me, there is some way to do it This process ?
final ArrayList<MovimientoCuenta> items = new ArrayList<>();
int cantidad = response.getMessageRS().getData().size();
int iterador = 0 ;
while(iterador<cantidad) {
MovimientoCuenta aux2 = new MovimientoCuenta(response.getMessageRS().getData().get(iterador).getDST(),
"USD "+response.getMessageRS().getData().get(iterador).getAMOUNT(), // este es el monto
response.getMessageRS().getData().get(iterador).getCURRENCY(),
response.getMessageRS().getData().get(iterador).getDATE(),""
,response.getMessageRS().getData().get(iterador).getREFERENCE(),"",
response.getMessageRS().getData().get(iterador).getSIGN(),
response.getMessageRS().getData().get(iterador).getNAME());
items.add(aux2);
iterador ++;
}
already tried
DecimalFormat formater = new DecimalFormat("###.00");
mount.setText(item.getMoneda() + " "+formater.format(Double.parseDouble(item.getMonto())));
Use the method
String.format()
to format the value:%.2f
means the following:You can perform a conversion to double from the String and apply a format that applies double decimal
"0.00"
, example:You would have as a result:
The same for the other values:
Applied to your Android code: