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

Javadoc of java.text.DecimalFormat is wrong

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7u75
    • core-libs
    • x86
    • windows_8

      A DESCRIPTION OF THE PROBLEM :
        /**
         * The {@link DecimalFormat} Javadoc says: <blockquote>That means that
         * <code>"#,##0.0#;(#)"</code> produces precisely the same behavior as
         * <code>"#,##0.0#;(#,##0.0#)"</code> .</blockquote>
         */
        @Test
        public void verifyDecimalFormatJavadoc() {
          DecimalFormat format1 = new DecimalFormat("#,##0.0#;(#)");
          DecimalFormat format2 = new DecimalFormat("#,##0.0#;(#,##0.0#)");
          BigDecimal positive = new BigDecimal("123.45");
          BigDecimal negative = positive.negate();

          assertEquals(format1.format(positive), format2.format(positive));
          assertEquals(format1.format(negative), format2.format(negative));
        }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The documentation should match what the code does. Or the code needs to match the documentation. I cannot tell which one is correct in this case.
      ACTUAL -
      That means that <code>"#,##0.0#;(#)"</code> produces precisely
       * the same behavior as <code>"#,##0.0#;(#,##0.0#)"</code>.

      URL OF FAULTY DOCUMENTATION :
      http://docs.oracle.com/javase/7/docs/api/java/text/DecimalFormat.html

            peytoia Yuka Kamiya (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: