8

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 ?

Matt R. Wilson
  • 7,268
  • 5
  • 32
  • 48
JavaUser
  • 81
  • 2

1 Answers1

16

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
Josh Lee
  • 171,072
  • 38
  • 269
  • 275