How to increase the java precision

Viewed 132

I am trying to make a Mandelbrot fractal zoom in java, but when the zoom increases, the double does not have enought precision and the image gets pixelated and I can not zoom more. I want to increase the precision or use another data type that allows me to that. Thank you.

1 Answers

You can use the BigDecimal class.

For example -

    BigDecimal a = new BigDecimal("0.000000000000000000000000000005");
    BigDecimal b = new BigDecimal("0.06");
    BigDecimal c = b.subtract(a);
    System.out.println(c);

EDIT: You can control the number of digits to the right of the decimal point using the setScale() method

    BigDecimal p=a.setScale(29, BigDecimal.ROUND_HALF_UP);
Related