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

java.text.DecimalFormat.format() incorrectly formats negative doubles

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      Name: dfC67450 Date: 01/26/98



      java.text.DecimalFormat.format(double, StringBuffer, FieldPosition) formats -0.0
      as -0 whereas -0.0001 as 0.
       
      Here is the test demonstrating the bug:

      -----------------Test.java------------------------
      import java.text.*;

      public class Test {
          public static void main (String args[]){
              DecimalFormat df = new DecimalFormat();
              double d1 = -0.0;
              double d2 = -0.0001;
              System.out.println("pattern: \"" + df.toPattern() + "\"");
              System.out.println(d1 + " is formatted as " +
                      df.format(d1, new StringBuffer(), new FieldPosition(0)));
              System.out.println(d2 + " is formatted as " +
                      df.format(d2, new StringBuffer(), new FieldPosition(0)));
          }
      }

      ---------Output from the test---------------------
      pattern: "#,##0.###"
      -0.0 is formatted as -0
      -1.0E-4 is formatted as 0
      --------------------------------------------------

      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              duke J. Duke (Inactive)
              Reporter:
              dfazunensunw Dmitri Fazunenko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: