I am trying to convert a list of doubles from a string format to a double format. I did this by putting them on a list and using a method Double.parseDouble(string).
This works for most numbers, but gives undesirable output, when double contains a trailing zero, the method parseDoubleremoves it. I do not want this to be deleted.
String[] values = {"124.50", "45.801", "-15.210"};
List<Double> nums = new ArrayList<Double>();
for(String s: values)
nums.add(Double.parseDouble(s));
Collections.sort(nums);
for(Double d: nums){
System.out.print(d + " ");
}
This gives the result:
-15.21 45.801 124.5
But I need trailing zeros. The problem with using a formatted string is that I will need to specify the floating point precision that I want when printing the values, but I have no specific desire to make the number accurate to a specific point, just leave only zeros if they are there .
Am I approaching this wrong?