Details
-
Wish
-
Status: Resolved
-
Major
-
Resolution: Won't Do
-
None
-
None
Description
Users of BigFraction might also be working with BigDecimal. Here's a simple way to convert BigDecimal to BigFraction:
public static BigFraction bigDecimalToBigFraction(BigDecimal bd) { int scale = bd.scale(); // If scale >= 0 then the value is bd.unscaledValue() / 10^scale if(scale >= 0) return new BigFraction(bd.unscaledValue(), BigInteger.TEN.pow(scale)); // If scale < 0 then the value is bd.unscaledValue() * 10^-scale return new BigFraction(bd.unscaledValue().multiply(BigInteger.TEN.pow(-scale))); }
It might be nice to have this incorporated into the BigFraction class as a constructor.
Attachments
Issue Links
- is superceded by
-
NUMBERS-32 MATH-1354 (fraction)
- Closed