JDK-4871921 : [Fmt-Nu] Incorrect number of significant digits in DecimalFormat scientific notation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.4.2,5.0,6
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: generic,windows_2000,windows_xp
  • CPU: generic,x86
  • Submitted: 2003-05-30
  • Updated: 2019-04-11
Related Reports
Duplicate :  
Description

Name: nt126004			Date: 05/30/2003


FULL PRODUCT VERSION :
java version "1.4.2-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-beta-b19)
Java HotSpot(TM) Client VM (build 1.4.2-beta-b19, mixed mode)

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
A DecimalFormat with the pattern "##0.##E0" does not give the expected number of significant digits when formatting the value 12345. This pattern and value are those used in the API documentation. The expected result is given there as "12.3E3", while the actual result is "12.345E3". The same result occurs with JDKs 1.3.1 and 1.4.1 so the discrepancy is not new.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code and compare the result with the API documentation!

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
12.3E3
123E3
1.23E6

ACTUAL -
12.345E3
123.46E3
1.2346E6


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.text.DecimalFormat;
	
class TestDecimalFormat
{
	public static void main(String[] args)
	{
		DecimalFormat f = new DecimalFormat("##0.##E0");
		try
		{
			System.out.println(f.format(12345));
			System.out.println(f.format(123456));
			System.out.println(f.format(1234567));
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
---------- END SOURCE ----------
(Review ID: 186640) 
======================================================================

Comments
EVALUATION Committed for Tiger. ###@###.### 2003-06-03 From API doc for DecimalFormat: Scientific Notation ... The number of significant digits in the mantissa is the sum of the minimum integer and maximum fraction digits, and is unaffected by the maximum integer digits. For example, 12345 formatted with "##0.##E0" is "12.3E3". To show all digits, set the significant digits count to zero. The number of significant digits does not affect parsing. The maximum integer digit had been used instead of the minimum integer digit. Fixed. ###@###.### 2003-10-20 I found that the fix for this bug has a side effect. Because the impact of this bug seems small, I decided not to fix this bug for tiger. ###@###.### 2003-10-22
20-10-2003