JDK-4087318 : double to string conversion are inaccurate in large numbers
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.1.4
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-10-20
  • Updated: 1997-10-20
  • Resolved: 1997-10-20
Related Reports
Duplicate :  
Description

Name: sg39081			Date: 10/20/97


This code will run a printout of all multiples of 10
greater than 1 000 000 right to 1.0E308.  This will
also count the number of bad conversions.  It 
should count 242 bad conversions.

public class mathtest
{
  public static void main(String[] args)
  {
    int badConversionCtr = 0;
    double d = 1000000D;

    for(int i = 1; i < 303; i++)
    {
      d = d * 10;
      System.out.println("double: " + d);

      if(String.valueOf(d).length() > 7)
        badConversionCtr++;
    }
    System.out.println("BadConversions: " + 
                      badConversionCtr);
    }
}

For example, the first inaccuracy occurs:
wrong:  9.999999999999999E22
right:  1.0E23

I've worked with Double.toString() and returns
the same error.

Thanks!
======================================================================

Comments
WORK AROUND Name: sg39081 Date: 10/20/97 ======================================================================
11-06-2004