JDK-6372330 : API doc for BigDecimal.toPlainString() is wrong
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.math
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp,windows_vista
  • CPU: x86
  • Submitted: 2006-01-13
  • Updated: 2011-02-16
  • Resolved: 2006-02-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b71Fixed
Related Reports
Duplicate :  
Relates :  
Description
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()

Comments
SUGGESTED FIX Replace * <tt>BigDecimal</tt> has a positive scale, the string resulting with * <tt>BigDecimal</tt> has a negative scale, the string resulting See bug 6362557 for full diffs.
31-01-2006

EVALUATION The submitter is correct; the documentation should be changed accordingly.
19-01-2006