Microsoft KB Archive/260968

= FIX: NumberFormat of a BigDecimal Truncates Fraction =

Article ID: 260968

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine, when used with:
 * Microsoft Windows 2000 Standard Edition
 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Software Development Kit for Java 2.02
 * Microsoft Software Development Kit for Java 3.0
 * Microsoft Software Development Kit for Java 3.0
 * Microsoft Software Development Kit for Java 3.1
 * Microsoft Software Development Kit for Java 3.2
 * Microsoft Software Development Kit for Java 4.0
 * Microsoft Visual J++ 6.0 Standard Edition

-



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.



Steps to Reproduce Behavior
 Compile and run the following code.  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(&quot;Double value = \t\t&quot;+bd.doubleValue); System.out.println(&quot;toString = \t\t&quot;+bd.toString); System.out.println(&quot;Number format = \t&quot;+nf.format(bd)); System.in.read; } }                   

