Package java.math

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


        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

    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

         */
        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

    // 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

      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

        }

        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

        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

      x = x.movePointLeft( scale );
    }

    if ( prec < nInit ) // for prec 15 root x0 must surely be OK
    {
      return x.round( rootMC );        // return small prec roots without iterations
    }
    // Initial v - the reciprocal
    BigDecimal v = BigDecimal.ONE.divide( TWO.multiply( x ), nMC );        // v0 = 1/(2*x)

    // Collect iteration precisions beforehand
View Full Code Here

    @Override
    public int sizePosition(Account account, DateTime time) {
        BigDecimal price = asset.priceAt(time);
        BigDecimal allocated = account.getCurrentAmount().multiply(ratio);
        BigDecimal shares = allocated.divide(price, 2, RoundingMode.HALF_UP);
        int i = shares.round(mc).intValue();

        return i;
    }
}
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.