FIX: NumberFormat of a BigDecimal Truncates Fraction (260968)



The information in this article applies to:

  • Microsoft virtual machine, when used with:
    • the operating system: Microsoft Windows 2000
  • Microsoft Internet Explorer (Programming) 4.0
  • Microsoft Internet Explorer (Programming) 4.01
  • Microsoft Internet Explorer (Programming) 4.01 SP1
  • Microsoft Internet Explorer (Programming) 4.01 SP2
  • Microsoft SDK for Java 2.0
  • Microsoft SDK for Java 3.0
  • Microsoft SDK for Java 3.0 Preview 1
  • Microsoft SDK for Java 3.1
  • Microsoft SDK for Java 3.2
  • Microsoft SDK for Java 4.0
  • Microsoft Visual J++ 6.0

This article was previously published under Q260968

SYMPTOMS

When you use the NumberFormat class to format a BigDecimal object, any digits following the decimal point will be truncated.

CAUSE

This is cause by a code defect.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug has been verified to occur in both the 3100 and 3200 series of the Microsoft virtual machine.

This problem was corrected in Windows 2000 Service Pack 1.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Compile and run the following code.
  2. Notice the output for the format() method compared to the doubleValue() method and the toString() method.

    NumberFormat.format() should include digits on the right side of the decimal point.
    import java.text.*;
    import java.math.*;
    
    public class NumberFormatTest { 
      public static void main (String[] args) throws Exception { 
        NumberFormat nf = NumberFormat.getInstance();
        BigDecimal bd = new BigDecimal(1234.56);
        System.out.println("Double value = \t\t"+bd.doubleValue());
        System.out.println("toString() = \t\t"+bd.toString());
        System.out.println("Number format = \t"+nf.format(bd));
        System.in.read();
      }
    }
    					

REFERENCES

For additional information about the latest service pack for Windows 2000, click the article number below to view the article in the Microsoft Knowledge Base:

260910 How to Obtain the Latest Windows 2000 Service Pack

For support information about Visual J++ and the SDK for Java, visit the following Microsoft Web site:

Modification Type:MajorLast Reviewed:6/14/2006
Keywords:kbBug kbfix kbJavaVM33xxfix kbWin2000sp1Fix KB260968