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!
======================================================================