Wrong result by Java Math.pow

后端 未结 6 1857
挽巷
挽巷 2020-12-06 17:17

If you try to run the following code

public class Main {
   public static void main(String[] args) {
       long a = (long)Math.pow(13, 15);
       System.ou         


        
6条回答
  •  一个人的身影
    2020-12-06 18:01

    it is because of the limit of holding digits in long by casting to double, float you may be able but it will have some errors, you should yourself handle the digits of the calculation by saving them in an array that's not an easy way

    but in python programming language you can have the result of any length, it is so powerful!

    be successful!!!

提交回复
热议问题