I'm trying to convert a String into double.
The source string is in the format "88.6" and the double I expect should be "88.60".
I tried converting using Double.parseDouble, Double constructor, Double.valueOf, DecimalFormat and NumberFormat hardcoding Locale.US or Locale.ENGLISH but I still get "88,600000".
How should I convert it?
Thanks
DecimalFormat df = new DecimalFormat("#.##", new DecimalFormatSymbols(Locale.US));
try {
dValue = df.parse(szValue).doubleValue();
} catch(ParseException e) {
e.printStackTrace();
}
While I don't think that keeping trailing zeros is necessary, I think this is what you are asking for:
the trailing zeros are only visible when printing them, so you just need to format the number