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

java.text.DecimalFormat.format() incorrectly uses maxFractionDigits setting

    XMLWordPrintable

Details

    • 1.1.6
    • sparc
    • solaris_2.5
    • Verified

    Backports

      Description



        Name: dfC67450 Date: 10/23/97



        java.text.DecimalFormat.format(double n, StringBuffer str, FieldPosition fp) formats
        wrong if `Math.pow(10, getMaximumFractionDigits()) * n' greater than Long.MAX_VALUE or
        less than Long.MIN_VALUE.
         
        Here is the test demonstrating the bug:

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

        public class Test {
            public static void main (String args[]){
                DecimalFormat df = new DecimalFormat();
                double d = 100;
                df.setMinimumFractionDigits(0);
                df.setMaximumFractionDigits(16);
                StringBuffer sBuf1 = new StringBuffer("");
                FieldPosition fp1 = new FieldPosition(0);
                System.out.println("d = " + d);
                System.out.println("maxFractionDigits = " + df.getMaximumFractionDigits());
                System.out.println(" format(d) = '" + df.format(d, sBuf1, fp1) + "'");
                System.out.println();
                df.setMaximumFractionDigits(17);
                StringBuffer sBuf2 = new StringBuffer("");
                FieldPosition fp2 = new FieldPosition(0);
                System.out.println("maxFractionDigits = " + df.getMaximumFractionDigits());
                System.out.println(" format(d) = '" + df.format(d, sBuf2, fp2) + "'");
            }
        }
        ---------Output from the test---------------------
        d = 100.0
        maxFractionDigits = 16
          format(d) = '100'
         
        maxFractionDigits = 17
          format(d) = '92.23372036854775807'
        --------------------------------------------------

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

        Attachments

          Issue Links

            Activity

              People

                joconnersunw John Oconner (Inactive)
                dfazunensunw Dmitri Fazunenko (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: