简体   繁体   English

Java:将两个BigInteger对象划分为一个BigDecimal对象

[英]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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM