JDK-4106664 : API: java.text.DecimalFormat.format(long n) fails if n * multiplier > MAX_LONG
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.3,1.1.6,1.2.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5,windows_nt
  • CPU: x86,sparc
  • Submitted: 1998-01-26
  • Updated: 2001-02-02
  • Resolved: 2001-02-02
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description

Name: dfC67450			Date: 01/26/98



java.text.DecimalFormat.format(long n, StringBuffer str, FieldPosition fp) formats 
wrong if `n * multiplier' greater than Long.MAX_VALUE.
 
Here is the test demonstrating the bug:

-----------------Test.java------------------------
import java.text.*;
import java.math.*;

public class Test {
    public static void main (String args[]){
        DecimalFormat df = new DecimalFormat();
        long n = 1234567890123456L;
        int m = 12345678;
        BigInteger bigN = BigInteger.valueOf(n);
        bigN = bigN.multiply(BigInteger.valueOf(m));
        df.setMultiplier(m); 
        df.setGroupingUsed(false); 
        System.out.println("formated: " + 
            df.format(n, new StringBuffer(), new FieldPosition(0)));
        System.out.println("expected: " + bigN.toString());
    }
} 

---------Output from the test---------------------
formated: 15241577640603568000000
expected: 15241577640603568023168
--------------------------------------------------

======================================================================

Comments
EVALUATION mark.son-bell@eng 1998-03-18 This requires an API change to fix. The API change request "BigInteger and BigDecimal Formatting" was refused for JDK 1.2. Name: saC57035 Date: 07/15/98 Requalifying this as a bug again, since it is actually a bug, no matter whether it requires API change or not. Mark, you may drop the priority of this report to P5 to put it out of the consideration for JDK 1.2FCS, but the JCK team needs an open bug report (not rfe) to exclude the test failing due to this bug. ======================================================================
11-06-2004