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

API doc for BigDecimal.toPlainString() is wrong

XMLWordPrintable

    • b71
    • x86
    • windows_xp, windows_vista

      A DESCRIPTION OF THE PROBLEM :
      The last two sentences of this javadoc read like this:

      "Note that if the result of this method is passed to the string constructor, only the numerical value of this BigDecimal will necessarily be recovered; the representation of the new BigDecimal may have a different scale. In particular, if this BigDecimal has a positive scale, the string resulting from this method will have a scale of zero when processed by the string constructor."

      This makes no sense because it would be an egregious bug if a BigDecimal constructed from a parsed String had a scale zero while the number represented by the original object had a positive scale. The last sentence should say "negative", instead of "positive". The method's source corroborates this:

          public String toPlainString() {
      BigDecimal bd = this;
      if (bd.scale < 0)
      bd = bd.setScale(0);
      .........

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      In particular, if this BigDecimal has a positive scale, the string resulting from this method will have a scale of zero when processed by the string constructor.
      ACTUAL -
      In particular, if this BigDecimal has a negative scale, the string resulting from this method will have a scale of zero when processed by the string constructor.

      URL OF FAULTY DOCUMENTATION :
      http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#toPlainString()

            darcy Joe Darcy
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: