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

[Fmt-Nu] NumberFormat.getPercentInstance() does not work correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 5.0u1, 6, 26
    • core-libs
    • None
    • Cause Known
    • generic
    • generic

      NumberFormat.getPercentInstance() does not work correctly for a double
      value. The attached test works fine with jdk 1.4.2.
      Platform


      import java.text.*;
      import java.util.*;

      public class Test {
          public static void main(String [] args) {
              NumberFormat fmt = NumberFormat.getPercentInstance();

              Test tt = new Test();
              tt.doTest(fmt, new Double(9223372036854775808.0));
              tt.doTest(fmt, new Double(-9223372036854775809.0));
          }

          public void doTest(NumberFormat fmt, Number value) {
              String s = fmt.format(value);
              String s2 = null;
              Number n = null;

              try {
                  n = fmt.parse(s);
                  s2 = fmt.format(n);

                  if (!s.equals(s2)) {
                     System.out.println("s is " + s);
                     System.out.println("s2 is " + s2);
                     System.out.println("FAIL");
                  }
              } catch (Exception e) {
                 e.printStackTrace();
              }
          }
      }

      Output:
      --------
      s is 922,337,203,685,477,600,000%
      s2 is 922,337,203,685,477,580,700%
      FAIL
      s is -922,337,203,685,477,600,000%
      s2 is -922,337,203,685,477,580,800%
      FAIL
      ###@###.### 10/11/04 22:39 GMT
      ###@###.### 10/11/04 23:21 GMT

            jlu Justin Lu
            psomashe Parvathi Somashekar (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: