danielgomezrico danielgomezrico - 2 months ago 14
Java Question

Format double value in scientific notation

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

Finally I do it by hand:

public static String parseToCientificNotation(double value) {
        int cont = 0;
        java.text.DecimalFormat DECIMAL_FORMATER = new java.text.DecimalFormat("0.##");
        while (((int) value) != 0) {
            value /= 10;
            cont++;
        }
        return DECIMAL_FORMATER.format(value).replace(",", ".") + " x10^ -" + cont;
}