JDK-4212074 : format function of NumberFormat/DecimalFormat
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.3
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-02-17
  • Updated: 1999-07-08
  • Resolved: 1999-07-08
Related Reports
Duplicate :  
Description

Name: nl37777			Date: 02/16/99


String s = "";
BigDecimal bd = new BigDecimal(""+4480.1900000000005);
bd = bd.setScale(2, BigDecimal.ROUND_HALF_UP);
System.out.println("Scale : " + bd.scale());        
System.out.println("Double : " + bd.doubleValue());
double pValue = bd.doubleValue();
System.out.println(pValue);
java.text.DecimalFormat nf = (DecimalFormat) NumberFormat.getCurrencyInstance();                
s = nf.format(pValue);
System.out.println("Return Value : " +  s);

for 4480.19 it always displays $4,480.18. But it works fine with other numbers.

If BigDecimal is not used it works fine.
(Review ID: 41248)
======================================================================

Comments
EVALUATION The note "If BigDecimal is not used it works fine" reveals all -- this is a duplicate of various other bugs that arise because the internal representation used by DecimalFormat is a double, not a BigDecimal. The fix for this is the same as the fix for the other bugs; to change the internal rep to a BigDecimal. This bug should be closed as a duplicate of 4106664; see also 4018937. alan.liu@eng 1999-03-23
23-03-1999