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

(fmt) Formatter.format("%0.4f\n", 56789.456789) generates MissingFormatWidthException

    XMLWordPrintable

Details

    • b100
    • x86
    • windows_xp
    • Verified

    Description

      FULL PRODUCT VERSION :
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]


      A DESCRIPTION OF THE PROBLEM :
      Formatters definition "The optional width is a non-negative decimal integer indicating the minimum number of characters to be written to the output." Using 0 as a width should be acceptable. The intention is to output the value regardless of width.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "%0.df should be equivalent to "%1.df"
      ACTUAL -
      Exception in thread "main" java.util.MissingFormatWidthException: 0.4f
              at java.util.Formatter$FormatSpecifier.checkNumeric(Formatter.java:2924)

              at java.util.Formatter$FormatSpecifier.checkFloat(Formatter.java:2903)
              at java.util.Formatter$FormatSpecifier.<init>(Formatter.java:2642)
              at java.util.Formatter.parse(Formatter.java:2477)
              at java.util.Formatter.format(Formatter.java:2411)
              at java.io.PrintStream.format(PrintStream.java:899)
              at java.io.PrintStream.printf(PrintStream.java:800)
              at TestFormat.main(TestFormat.java:9)

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      MissingFormatWidthException

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class TestFormat
      {
      public static void main(String argv[])
      {
      System.out.printf("%1.4f\n", 56789.456789);
      System.out.printf("%0.4f\n", 56789.456789);
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use %1.df rather than %0.df
      ###@###.### 10/13/04 21:12 GMT

      Attachments

        Activity

          People

            bpb Brian Burkhalter
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: