/* package whatever; // don't place package name! */

import java.math.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
        int bdErrors = 0, doubleErrors = 0;
        for(BigDecimal bd = BigDecimal.ZERO; bd.compareTo(BigDecimal.ONE) <=0 ; bd = bd.add(new BigDecimal("0.0001"))) {
            // test BigDecimal rounds as expected.
            BigDecimal bd2 = bd.setScale(2, RoundingMode.HALF_UP);
            BigDecimal error = bd2.remainder(new BigDecimal("0.01"));
            if (error.compareTo(BigDecimal.ZERO) != 0)
                bdErrors++;
            // now try this with double.
            double d = bd.doubleValue();
            double d2 = Math.round(d * 100) / 100.0;

            // has any information been lots, use BigDecimal to do calculations to be sure of no accidental errors.
            BigDecimal bd3 = BigDecimal.valueOf(d2);
            BigDecimal error3 = bd3.remainder(new BigDecimal("0.01"));
            if (error3.compareTo(BigDecimal.ZERO) != 0)
                doubleErrors++;

        }
        System.out.printf("BigDecimal errors %,d & double errors %,d%n", bdErrors, doubleErrors);
	}
}