How to divide two large integers in java? [closed]

本秂侑毒 提交于 2019-12-13 08:46:19

问题


I want to divide two large integers,

a = 23546654
b = 24979799

and to get the result in double.


回答1:


Try

double x = ((double) a) / ((double) b)

which first converts your ints to doubles and then does the division. If you have BigIntegers (which your tag indicates) you may use BigInteger.doubleValue() to extract the double value.




回答2:


This are plain int rather than BigInteger.

All you need is

double ratio = (double) a / b;



回答3:


BigInteger class has a divide method.

BigInteger result = a.divide(b);


来源:https://stackoverflow.com/questions/8727587/how-to-divide-two-large-integers-in-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!