United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4092330 : RFE: Precision, rounding in NumberFormat

Details
Type:
Enhancement
Submit Date:
1997-11-12
Status:
Resolved
Updated Date:
2005-02-28
Project Name:
JDK
Resolved Date:
2005-02-28
Component:
core-libs
OS:
windows_nt,linux,generic,windows_98,windows_95
Sub-Component:
java.text
CPU:
x86,generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.1.4,1.3.0,1.3.1,1.4.0,5.0
Fixed Versions:

Related Reports
Duplicate:
Duplicate:
Relates:

Sub Tasks

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
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
                                     
2000-02-14
WORK AROUND



Name: rm29839			Date: 11/12/97



======================================================================
                                     
2004-08-06



Hardware and Software, Engineered to Work Together