There is a similar SO question that suggests using NumberFormat, which I did.
I am using the parse () method for NumberFormat.
public static void main(String[] args) throws ParseException{
DecToTime dtt = new DecToTime();
dtt.decToTime("1.930000000000E+02");
}
public void decToTime(String angle) throws ParseException{
DecimalFormat dform = new DecimalFormat();
Number angleAsNumber = dform.parse(angle);
System.out.println(angleAsNumber);
}
The result is
1.93
I really did not expect this to work because 1.930000000000E + 02 is a rather unusual looking number, do I need to parse strings first to remove zeros? Or is there a quick and elegant way?
Ankur source
share