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

NumberFormat incorrectly formats fraction digits

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1.2
    • core-libs
    • None
    • x86
    • windows_95



      Name: mc57594 Date: 06/19/97


      Using java.util.NumberFormat, the double 1.005 is formatted to
      1.0049 if asked to use 4 fraction digits.

      import java.awt.TextField;
      import java.text.*;
      import java.util.*;

      public class TestNumberFormat
      {
      public static void main(String [] args)
      {
         String myString = new String("1.0050");
         NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
         nf.setGroupingUsed(false);
         nf.setMaximumFractionDigits(4);
         nf.setMinimumFractionDigits(4);
         Number myNumber = new Double(0);
         System.out.println("String non formatted: "+ myString);
         try
         {
           myNumber = new Double(myString);
         }
         catch (Exception E)
         { }
         myString = nf.format(myNumber);
         System.out.println("String formatted: "+ myString);
      }
      }

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

            Unassigned Unassigned
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: