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

Formatting .5 rounds to "1" instead of "0". (Regression in 1.2.2 RC1)

    XMLWordPrintable

Details

    • 1.2.2
    • generic
    • generic

    Description



      Name: skT88420 Date: 06/01/99


      When rounding the value .5 using a pattern that specifies no digits after the decimal point, the value should be rounded to zero, according to the "half even" algorithm. This worked in 1.2, but in 1.2.2 RC1 it gets rounded to one instead.

      import java.text.*;
      public class DoubleFormatTest
      {
      public final static void main (String[] args)
      {
      format(0.5, "0.", "0."); // Fails under 1.2.2rc1, OK under 1.2
      format(1.5, "0.", "2.");
      format(2.5, "0.", "2.");
      format(3.5, "0.", "4.");
      format(4.5, "0.", "4.");
      }

      private static void format(double d, String pattern, String expected)
      {
      DecimalFormat format = new DecimalFormat(pattern);
      String result = format.format(d);
      if (result.equals(expected))
      System.out.println("OK: got " + result);
      else
      System.out.println("FAIL: got " + result + " expected " + expected);
      }
      }


      Output:
      FAIL: got 1. expected 0.
      OK: got 2.
      OK: got 2.
      OK: got 4.
      OK: got 4.
      (Review ID: 83764)
      ======================================================================

      Attachments

        Activity

          People

            aliusunw Alan Liu (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: