除以大整数得到确切的价值整数、确切、价值

2023-09-11 06:58:00 作者:夜长梦多@

我想找到的值 1 /(2 ^ N),其中 0℃= N< = 200

我曾尝试使用的BigInteger,但它给输出为零。我想分割后确切的数字。

I have tried to use biginteger but it is giving output as zero . I want exact number after division .

import java.math.BigInteger;


public class Problem2 {
    public static void main(String args[]){
        BigInteger bi1 =  new BigInteger("2").pow(200);
        BigInteger bi2 =    BigInteger.ONE;

         BigInteger bi3 = bi2.divide(bi1);
         System.out.println(bi3);  //why it giving output zero
    }
}

在使用BigDecimal的它给指数值,但如何获得准确的值,而指数。

On use of BigDecimal it is giving exponential value , but how to get exact value without exponent.

推荐答案

由于0℃ BI3和小于1,所以一个整数结果很到位的BigInteger

because 0< bi3 <1, so an integer result is 0. Try BigDecimal in place of BigInteger

 
精彩推荐
图片推荐