Format double value in scientific notation

Daniel Gomez Rico picture Daniel Gomez Rico · May 31, 2010 · Viewed 85.5k times · Source

I have a double number like 223.45654543434 and I need to show it like 0.223x10e+2.

How can I do this in Java?

Answer

Peter Tillemans picture Peter Tillemans · May 31, 2010
    System.out.println(String.format("%6.3e",223.45654543434));

results in

    2.235e+02

which is the closest I get.

more info : http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html#syntax