Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4106664

API: java.text.DecimalFormat.format(long n) fails if n * multiplier > MAX_LONG

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86, sparc
    • OS:
      solaris_2.5, windows_nt

      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
      --------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              nlindenbsunw Norbert Lindenberg (Inactive)
              Reporter:
              dfazunensunw Dmitri Fazunenko (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: