Convert scientific notation to decimal notation

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-03-15T16:05:48Z Indexed on 2010/03/15 16:09 UTC
Read the original article Hit count: 410

Filed under:
|
|

There is a similar question on SO which suggests using NumberFormat which is what I have done.

I am using the parse() method of 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();
    //ParsePosition pp = new ParsePosition(13);
    Number angleAsNumber = dform.parse(angle);

    System.out.println(angleAsNumber);
}

The result I get is

1.93

I didn't really expect this to work because 1.930000000000E+02 is a pretty unusual looking number, do I have to do some string parsing first to remove the zeros? Or is there a quick and elegant way?

© Stack Overflow or respective owner

Related posts about java

Related posts about numbers