Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4330377

DecimalFormat engineering notation gives incorrect results

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.3.1
    • 1.3.0
    • core-libs
    • ladybird
    • generic
    • generic



        Name: skT45625 Date: 04/13/2000


        java version "1.3.0rc2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0rc2-Y)
        Java HotSpot(TM) Client VM (build 1.3.0rc2-Y, mixed mode)

        Using engineering notation such as ##0.#E0 with numbers less than 1 often gives
        incorrect results.

        This program:
            import java.text.*;
            public class DecForm {
                public static void main(String args[]) {
                    test(0.05);
                    test(0.005);
                    test(0.0005);
                }
                static void test(double d) {
                    test(d, "000.#E0");
                    test(d, "##0.#E0");
                    test(d, "#00.#E0");
                    System.out.println();
                }
                static void test(double d, String f) {
                    DecimalFormat df = new DecimalFormat(f);
                    System.out.print(f + " " + df.format(d) + " ");
                }
            }

        Produces the output:
            000.#E0 500E-4 ##0.#E0 5E-3 #00.#E0 50E-3
            000.#E0 500E-5 ##0.#E0 5E-3 #00.#E0 5.0E-3
            000.#E0 500E-6 ##0.#E0 5E-6 #00.#E0 50E-6

        The last line of output says that 500E-6 = 5E-6 = 50E-6. Clearly, these results
        are incorrect.
        (Review ID: 103664)
        ======================================================================

              nlindenbsunw Norbert Lindenberg (Inactive)
              skondamasunw Suresh Kondamareddy (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: