nd4j-common/src/main/java/org/nd4j/linalg/util/BigDecimalMath.java
static public BigDecimal multiplyRound(final BigDecimal x, final Rational f) {
        if (f.compareTo(BigInteger.ZERO) == 0) {
            return BigDecimal.ZERO;
        } else {
            /* Convert the rational value with two digits of extra precision
             */
            MathContext mc = new MathContext(2 + x.precision());
            BigDecimal fbd = f.BigDecimalValue(mc);
            /* and the precision of the product is then dominated by the precision in x
             */


            return multiplyRound(x, fbd);


        }
    }
static public BigDecimal multiplyRound(final BigDecimal x, final Rational f) {
        if (f.compareTo(BigInteger.ZERO) == 0) {
            return BigDecimal.ZERO;
        } else {
            /* Convert the rational value with two digits of extra precision
             */
            MathContext mc = new MathContext(2 + x.precision());
            BigDecimal fbd = f.BigDecimalValue(mc);
            /* and the precision of the product is then dominated by the precision in x
             */


            return multiplyRound(x, fbd);


        }
    }
Multiply and round.

@param x The left factor.
@param f The right factor.
@return The product x*f.