commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gilles (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (MATH-1354) Easy conversion from BigDecimal to BigFraction
Date Sat, 22 Apr 2017 16:44:04 GMT

     [ https://issues.apache.org/jira/browse/MATH-1354?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Gilles updated MATH-1354:
-------------------------
           Labels: commons-numbers  (was: )
    Fix Version/s:     (was: 4.X)
                   4.0

Issue to be moved to NUMBERS.

> Easy conversion from BigDecimal to BigFraction
> ----------------------------------------------
>
>                 Key: MATH-1354
>                 URL: https://issues.apache.org/jira/browse/MATH-1354
>             Project: Commons Math
>          Issue Type: Wish
>            Reporter: Dobes Vandermeer
>              Labels: commons-numbers
>             Fix For: 4.0
>
>
> Users of BigFraction might also be working with BigDecimal.  Here's a simple way to convert
BigDecimal to BigFraction:
> {code}
>     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)));
>     }
> {code}
> It might be nice to have this incorporated into the BigFraction class as a constructor.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message