views:

33

answers:

3

What is an easy way to get the integral part of a BigFraction as a BigInteger?

Basically I want the same result that the intValue and longValue methods return but with arbitrary precision.

I also want to avoid rounding so indirect conversion via a BigDecimal is not suitable.

+2  A: 

 

myBigFraction.getNumerator().divide( myBigFraction.getDemoninator() );

?

mobrule
Unsurprisingly `BigFraction.longValue()` is implemented this way. The surprising part is that there is no `bigIntegerValue()` method.
finnw
A: 

You could try something like this

BigFraction fraction = ...

BigInteger num = fraction.getNumerator();
BigInteger den = fraction.getDenominator();
BigInteger[] divideAndReminder = num.divideAndRemainder(den);

Then finally

BigInteger integralPart = divideAndReminder[0];
Lombo
A: 

This should do the trick.

bigInteger = bigFraction.genNumerator().divide(bigFraction.getDenominator());
torak