Package java.math

Examples of java.math.RoundingMode


  private void initMoney(ServletConfig aConfig){
    String moneyStyle = fDecimalStyle.fetch(aConfig).getValue();
    String DELIMITER = ",";
    StringTokenizer parser = new StringTokenizer(moneyStyle, DELIMITER);
    RoundingMode rounding = RoundingMode.valueOf(parser.nextToken());
    Integer numDecimals = Integer.valueOf(parser.nextToken());
    Decimal.init(rounding, numDecimals);
  }
View Full Code Here


    }

    @JRubyMethod(name = "round", optional = 2)
    public IRubyObject round(ThreadContext context, IRubyObject[] args) {
        int scale = args.length > 0 ? num2int(args[0]) : 0;
        RoundingMode mode = (args.length > 1) ? javaRoundingModeFromRubyRoundingMode(args[1]) : getRoundingMode(context.runtime);
        // JRUBY-914: Java 1.4 BigDecimal does not allow a negative scale, so we have to simulate it
        if (scale < 0) {
          // shift the decimal point just to the right of the digit to be rounded to (divide by 10**(abs(scale)))
          // -1 -> 10's digit, -2 -> 100's digit, etc.
          BigDecimal normalized = value.movePointRight(scale);
View Full Code Here

        RubyBigDecimal res = handleAddSpecialValues(val);
        if (res != null) {
            return res;
        }
        RoundingMode roundMode = getRoundingMode(runtime);
        return new RubyBigDecimal(runtime, value.add(
                val.value, new MathContext(prec, roundMode))); // TODO: why this: .setResult();
    }
View Full Code Here

            return null;

        try {
            Double       num    = (Double)input.get(0);
            Integer      digits = (Integer)input.get(1);
            RoundingMode mode   = (input.size() >= 3) ?
                RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN;
            if (num == null) return null;

            BigDecimal bdnum  = BigDecimal.valueOf(num);
            bdnum = bdnum.setScale(digits, mode);
View Full Code Here

            return null;

        try {
            Float        num    = (Float)input.get(0);
            Integer      digits = (Integer)input.get(1);
            RoundingMode mode   = (input.size() >= 3) ?
                RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN;
            if (num == null) return null;

            BigDecimal bdnum  = BigDecimal.valueOf(num);
            bdnum = bdnum.setScale(digits, mode);
View Full Code Here

            return null;

        try {
            Double       num    = DataType.toDouble(input.get(0));
            Integer      digits = DataType.toInteger(input.get(1));
            RoundingMode mode   = (input.size() >= 3) ?
                RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN;
            if (num == null) return null;

            BigDecimal bdnum  = BigDecimal.valueOf(num);
            bdnum = bdnum.setScale(digits, mode);
View Full Code Here

            return null;

        try {
            Double       num    = DataType.toDouble(input.get(0));
            Integer      digits = DataType.toInteger(input.get(1));
            RoundingMode mode   = (input.size() >= 3) ?
                RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN;
            if (num == null) return null;

            BigDecimal bdnum  = BigDecimal.valueOf(num);
            bdnum = bdnum.setScale(digits, mode);
View Full Code Here

            return null;

        try {
            Float        num    = (Float)input.get(0);
            Integer      digits = (Integer)input.get(1);
            RoundingMode mode   = (input.size() >= 3) ?
                RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN;
            if (num == null) return null;

            BigDecimal bdnum  = BigDecimal.valueOf(num);
            bdnum = bdnum.setScale(digits, mode);
View Full Code Here

            return null;

        try {
            Double       num    = (Double)input.get(0);
            Integer      digits = (Integer)input.get(1);
            RoundingMode mode   = (input.size() >= 3) ?
                RoundingMode.valueOf(DataType.toInteger(input.get(2))) : RoundingMode.HALF_EVEN;
            if (num == null) return null;

            BigDecimal bdnum  = BigDecimal.valueOf(num);
            bdnum = bdnum.setScale(digits, mode);
View Full Code Here

        String a = "-37361671119238118911893939591735";
        int aScale = 10;
        String b = "74723342238476237823787879183470";
        int bScale = -15;
        int newScale = 31;
        RoundingMode rm = RoundingMode.UP;
        String c = "-5.00000E-26";
        BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
        BigDecimal bNumber = new BigDecimal(new BigInteger(b), bScale);
        BigDecimal result = aNumber.divide(bNumber, newScale, rm);
        assertEquals("incorrect value", c, result.toString());
View Full Code Here

TOP

Related Classes of java.math.RoundingMode

Copyright © 2018 www.massapicom. 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.