I want to compute numbers with arbitrarily long decimal values (suppose I want to take a 100 decimal digits for a particular number).
//Take the square root of 2 for 100 digits in total.
public class Main {
public static void main(String[] args) {
BigDecimal root2 = new BigDecimal(Math.pow(2, 0.5));
root2 = root2.setScale(99, BigDecimal.ROUND_HALF_UP);
System.out.println(root2);
}
}
And this program outputs:
1.414213562373095145474621858738828450441360473632812500000000000000000000000000000000000000000000000
Having a beginner background in the storage of bytes, I realize the issue here is either the output format, or the fact that I'm still not getting the precision I'm looking for since it doesn't use the memory I'm expecting it to. Any suggestions? Is it possible to get precision this high? I'm not against turning to Mathematica.
For clarification: I'm trying to get the full precision of 100 digits (the zeros do not belong here).