Examples of round()


Examples of java.math.BigDecimal.round()

        BigDecimal resul = x.multiply(y);
        /* The estimation of the relative error in the result is the sum of the relative
         * errors |err(y)/y|+|err(x)/x|
         */
        MathContext mc = new MathContext(Math.min(x.precision(), y.precision()));
        return resul.round(mc);
    } /* multiplyRound */

    /** Multiply and round.
     * @param x The left factor.
     * @param y The right factor.
View Full Code Here

Examples of java.math.BigDecimal.round()

        BigDecimal resul = x.multiply(new BigDecimal(n));
        /*
         * The estimation of the absolute error in the result is |n*err(x)|
         */
        MathContext mc = new MathContext(n != 0 ? x.precision(): 0);
        return resul.round(mc);
    }

    /** Multiply and round.
     * @param x The left factor.
     * @param n The right factor.
View Full Code Here

Examples of java.math.BigDecimal.round()

        BigDecimal resul = x.multiply(new BigDecimal(n));
        /*
         * The estimation of the absolute error in the result is |n*err(x)|
         */
        MathContext mc = new MathContext(n.compareTo(BigInteger.ZERO) != 0 ? x.precision(): 0);
        return resul.round(mc);
    }

    /** Divide and round.
     * @param x The numerator
     * @param y The denominator
View Full Code Here

Examples of java.math.BigDecimal.round()

        startAt.isGoodArgsCnt(1);
        BigDecimal n = number.get();
        //int digits=Math.abs(n.precision()-n.scale());
        //System.out.println("integer part:"+digits+", precision:"+number.precision());
        MathContext mc=context.get();
        return new Node(n.round(new MathContext(Math.max(n.precision(),mc.getPrecision()),mc.getRoundingMode())).stripTrailingZeros().toPlainString());
    }

    /**
     * Retourne le Decimal sous la forme d'une chaîne de caractères dans la Engineering (avec puissances de 10).
     *
 
View Full Code Here

Examples of java.math.BigDecimal.round()

    public Node external_string_E(Node startAt) throws Exception {
        startAt.isGoodArgsCnt(1);
        BigDecimal n = number.get();
        int digits=BigDecimalMath.getIntDigitsCnt(n);
        MathContext mc=context.get();
        return new Node(n.round(new MathContext(digits+mc.getPrecision(),mc.getRoundingMode())).stripTrailingZeros().toEngineeringString());
    }

    /*
     *
     */
 
View Full Code Here

Examples of java.math.BigDecimal.round()

         */
        BigDecimal r = number.get();
        for (int i = 1; i < asize; )
            r = r.subtract(_getArg_(startAt, i++));
        MathContext mc=context.get();
        return Node.createExternal(new External_Decimal(r.round(mc), mc));
    }

    /**
     * surcharge de l'opérateur -!
     *
 
View Full Code Here

Examples of java.math.BigDecimal.round()

    // First limit the number of digits and then the precision.
    // Try and round to 29 digits because we can sometimes do that
    BigInteger allWordBigInt;
    allWordBigInt = destinationDecimal.unscaledValue();
    if (allWordBigInt.bitLength() > 96) {
      destinationDecimal = destinationDecimal.round(new MathContext(29));
      // see if 29 digits uses more than 96 bits
      if (allWordBigInt.bitLength() > 96) {
        // Dang. It was over 97 bits so shorten it one more digit to
        // stay <= 96 bits
        destinationDecimal = destinationDecimal.round(new MathContext(
View Full Code Here

Examples of java.math.BigDecimal.round()

      destinationDecimal = destinationDecimal.round(new MathContext(29));
      // see if 29 digits uses more than 96 bits
      if (allWordBigInt.bitLength() > 96) {
        // Dang. It was over 97 bits so shorten it one more digit to
        // stay <= 96 bits
        destinationDecimal = destinationDecimal.round(new MathContext(
            28));
      }
    }
    // the bit manipulations above may change the scale so do it afterwards
    // round the scale to the max MS can support
View Full Code Here

Examples of java.math.BigDecimal.round()

        }

        BigDecimal res = value.multiply(val.value);
        if (res.precision() > digits) {
            // TODO: rounding mode should not be hard-coded. See #mode.
            res = res.round(new MathContext(digits,  RoundingMode.HALF_UP));
        }
        return new RubyBigDecimal(runtime, res).setResult();
    }
   
    @JRubyMethod(name = {"**", "power"}, required = 1)
View Full Code Here

Examples of java.math.BigDecimal.round()

        sb.append(')');
    }
    if(parent!=null){
        double dis= DistanceMatrix.getDistanceFromPar(n, parent, par.cpar);
        BigDecimal bd = new BigDecimal(dis);
        String str=bd.round(new MathContext(3)).toString();
        sb.append(":");
        sb.append(str);
    }
}
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.