JDK-4092330 : RFE: Precision, rounding in NumberFormat
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.4,1.3.0,1.3.1,1.4.0,5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    generic,linux,windows_95,windows_98,windows_nt generic,linux,windows_95,windows_98,windows_nt
  • CPU: generic,x86
  • Submitted: 1997-11-12
  • Updated: 2017-05-16
  • Resolved: 2005-02-28
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 b26Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
Name: rm29839			Date: 11/12/97


Using NumberFormat we sould get formatted strings.

Suppose I perform all my Money arthimetic using 
double type. Now I Need to round the number to the 
nearest penny, I should be able to do that by 
associating a Precision Class to Format which will
produce the correct String. 
This is just a suggession
(Review ID: 19509)
======================================================================

Name: jl125535			Date: 01/23/2002


It might be a good idea for java.text.NumberFormat to support rounding modes besides half_even (see getIntegerInstance()). A feature like  java.lang.BigDecimal.setScale(int scale, int roundingMode) would allow the selection of a rounding mode.
(Review ID: 138628)
======================================================================

Name: gm110360			Date: 02/16/2002


FULL PRODUCT VERSION :
java version "1.4.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-rc-b91)
Java HotSpot(TM) Client VM (build 1.4.0-rc-b91, mixed mode)
-- same problem with
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

FULL OPERATING SYSTEM VERSION : Windows NT Version 4.0
Build 1381, Service Pack 6


A DESCRIPTION OF THE PROBLEM :
DecimalFormat: A pattern like "##0.000E0" does not produce
three fraction digits if the fraction part is close or equal
to zero.
 
However, this is needed in ouptut of
- results from scientific computation
- y-Axis tic labels in charting applications

There is a related RFE, that is driven by the same
requirement: 4092330

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile the attached source "DecimalFormatTest.java"
2. Execute
3. Look at the console output

EXPECTED VERSUS ACTUAL BEHAVIOR :
--Actual output of DecimalFormatTest.java:
12.345E3
12.00E3
12.001E3
12.0003E3
12.0007E3
12.00E3
--Expected:
12.345E3
12.000E3
12.001E3
12.000E3
12.001E3
12.000E3

This bug can be reproduced always.

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

public class DecimalFormatTest {

public static void main(String[] args) {

DecimalFormat df = new DecimalFormat("##0.000E0"); // three fraction digits !
System.out.println(df.format(12345.0)); // "12.345E3", OK
System.out.println(df.format(12000.0)); // "12.00E3", BUG
System.out.println(df.format(12001.0)); // "12.001E3", OK
System.out.println(df.format(12000.3)); // "12.0003E3", BUG
System.out.println(df.format(12000.7)); // "12.0007E3", BUG
System.out.println(df.format(12000.03)); // "12.00E3", BUG
}
}
---------- END SOURCE ----------
(Review ID: 139590)
======================================================================
###@###.### 11/5/04 00:50 GMT

Comments
WORK AROUND Name: rm29839 Date: 11/12/97 ======================================================================
06-08-2004

EVALUATION I don't find much support on this request. Clsoing as "will not fix". masayoshi.okutsu@Eng 2000-02-14 Implementing this feature, as this is a pre-requisite for the pluggable locales project, by adding get/setRoundingMode() methods. ###@###.### 2005-2-11 23:55:17 GMT
14-02-2000