JDK-8165466 : DecimalFormat percentage format can contain unexpected %
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-09-02
  • Updated: 2018-05-14
  • Resolved: 2016-10-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 8 JDK 9
8u172Fixed 9 b139Fixed
Related Reports
Duplicate :  
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Windows Server 2012, OSX

A DESCRIPTION OF THE PROBLEM :
Multiple calls to DecimalFormat when formatting percentages can lead to extra % in the output

REGRESSION.  Last worked in version 7u80

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
0.006%
0%
0.006%
ACTUAL -
0.006%
0%
0%006%

REPRODUCIBILITY :
This bug can be reproduced occasionally.

---------- BEGIN SOURCE ----------
import java.text.*;

public class DecFormats {

	public static void main(String[] args) {
		DecimalFormat nf = (DecimalFormat) DecimalFormat.getPercentInstance(new java.util.Locale("en_US"));
		nf.setMaximumFractionDigits(3);
		nf.setMinimumFractionDigits(0);
		nf.setMultiplier(1);
		System.out.println(nf.format(.005678));
		System.out.println(nf.format(0.0));
		System.out.println(nf.format(.005678));
	}

}
---------- END SOURCE ----------


Comments
To reproduce the issue , run the attached test case. Following are the results on various JDK versions: JDK 7u80- Pass JDK 8 - Fail JDK 8u102 - Fail JDK 8u112 ea - Fail JDK 9ea +128 - Fail Following is the output on JDK 7u80: 0.006% 0% 0.006% Following is the output on rest of the versions: 0.006% 0% 0%006%
06-09-2016