Hi all,
I am new to the forums, but am hoping someone can help me out.
I am trying to figure some things out:
Using M$ Windows calculator - if you enter 5 sqrt * = you get 5 - same as sqrt(5) * sqrt(5)
In
java i have tried:
BigDecimal bd1 = new BigDecimal(Math.sqrt(5)).setScale(32, BigDecimal.ROUND_HALF_UP);
BigDecimal bd2 = bd1;
System.out.println(bd1.multiply(bd1).toString());
This outputs: 5.0000000000000004858631542817679579261519802454185847561882183321
instead of 5
I have also tried:
System.out.println(Math.sqrt(5) * Math.sqrt(5));
this outputs: 5.000000000000001
Also using M$ calculator - 1 / 3 * 3 returns 1.
I tried this with BigDecimal:
bd1 = new BigDecimal("3").setScale(32, BigDecimal.ROUND_HALF_UP);
bd2 = new BigDecimal("1").setScale(32, BigDecimal.ROUND_HALF_UP);
System.out.println(bd2.divide(bd1, BigDecimal.ROUND_HALF_UP).multiply(bd1).toString());
and get: 0.9999999999999999999999999999999900000000000000000000000000000000
Maybe I need to refactor this equation to be (1 * 3) / 3 - this would return 1.
I am trying to build a calculator, but I can't seem to work through some of these issues.
Any help is greatly appreciated.