Android string formatiing from xml
- by mann
I am parsing xml from server. One of its node contains data like
<distance>16.3432434324354324km</distance>
I am putting it into hashmap like
for (int i = 0; i < nl.getLength(); i++) {
map.put(KEY_DISTANCE, parser.getValue(e, KEY_DISTANCE));
// adding HashList to ArrayList
menuItems.add(map);
}
Everything is nice. But i want it two decimal places for example i want its value should be
16.34km rather then 16.343234324342342km
I tried with
DecimalFormat twoDForm=new DecimalFormat("##.00");
try{
Double StartVTwo=Double.valueOf(KEY_DISTANCE);
Double resultDouble1 = Double.valueOf(twoDForm.format(StartVTwo));
Log.e("check", String.valueOf(resultDouble1));
}catch (NumberFormatException e){
Log.e("error"," This is error ");
}
But it shows exception and prints this message.
Any help would be appreciated!!