when I use Math.pow(9, 18) =150094635296999136
when I use web Calculator 9^18 = 150094635296999121 (http://web2.0calc.com/)
when I use Google calculator 9^18 = 1.50094635 × 10^17
why it is different ?
when I use Math.pow(9, 18) =150094635296999136
when I use web Calculator 9^18 = 150094635296999121 (http://web2.0calc.com/)
when I use Google calculator 9^18 = 1.50094635 × 10^17
why it is different ?
At that range, the difference between successive double
values is 32. 150094635296999121 is the correct answer as an integer, but that number cannot be exactly represented as a double
.
You can use BigInteger
to get the exact answer:
Math.pow(9, 18) == 150094635296999136
BigInteger.valueOf(9).pow(18) == 150094635296999121