import java.math.BigDecimal;

import static org.junit.Assert.*;

import org.hamcrest.Matchers;
import org.junit.Test;

public class Main {
    final String stringRepresentation = "0212467111917324511";
    // after the conversion to double value is 2.12467111917324512E17 (this is OK)
    final double parsedDouble = Double.parseDouble(stringRepresentation);
    // after conversion to string - value is: 2.124671119173245E17 (last two digits are lost due to the new way of toString method in the Double class)
    final String backFromDouble = Double.toString(parsedDouble);
    // conversion back to double brings again the original value: 2.12467111917324512E17
    final double parsedFromBackFromDouble = Double.parseDouble(backFromDouble);

    // with the usage of constructor BigDecimal holds the same value as parsedDouble: 212467111917324512
    final BigDecimal bigDecimalFromDouble = new BigDecimal(parsedDouble);
    // with the usage of valueOf(double) precession is lost due to the new 'toString' method in the Double class: 2.12467111917324512E17
    final BigDecimal bigDecimalFromValueOf = BigDecimal.valueOf(parsedDouble);
    @Test
    public void testDoubleConversion() {
        assertEquals(parsedDouble, parsedFromBackFromDouble);
    }

    @Test
    public void testBigDecimalConversion() {

        // compare fail due to the fact that 'bigDecimalFromDouble' is greater number (due to the lost of last 2 digits in 'valueOf' conversion)
        assertThat(bigDecimalFromDouble, Matchers.comparesEqualTo(bigDecimalFromValueOf));
    }


}