[英]Java: divide two BigInteger Objects into a BigDecimal object
What is the easiest way, using the least amount of unnecessary overhead to divide two BigInteger objects and store it in a BigDecimal Object? 什么是最简单的方法,使用最少的不必要的开销来划分两个BigInteger对象并将其存储在BigDecimal对象中?
I have been trying to work around the problem and cannot find anything that does not use an extremely excessive amount of conversions. 我一直在努力解决这个问题,找不到任何不使用过多转换的东西。
Edit: Realized how stupid this question was, I'll leave it up for reference though 编辑:意识到这个问题有多愚蠢,我会把它留作参考
You can convert your BigIntegers into BigDecimals: 您可以将BigIntegers转换为BigDecimals:
// bigIntX is a BigInteger
BigDecimal bigDecX = new BigDecimal(bigIntX);
BigDecimal bigDecY = new BigDecimal(bigIntY);
// to divide:
bigDecX.divide(bigDecY);
Convert both BigInteger
to BigDecimal
and then divide them. 将
BigInteger
转换为BigDecimal
,然后将它们分开。
see: http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html#BigDecimal(java.math.BigInteger) 请参阅: http : //docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html#BigDecimal(java.math.BigInteger)
http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html#divide(java.math.BigDecimal) http://docs.oracle.com/javase/1.5.0/docs/api/java/math/BigDecimal.html#divide(java.math.BigDecimal)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.