Package java.math

Examples of java.math.BigDecimal.precision()


   * @throws TransformationException if value is an incorrect input type or
   * the transformation fails
   */
  public Object transformDirect(Object value) throws TransformationException {
    BigDecimal result = BigDecimal.valueOf(((Number)value).doubleValue());
    result = result.setScale(Math.max(result.scale(), (value instanceof Double ? 16 : 8) - result.precision()));
    return result;
  }

  /**
   * Type of the incoming value.
View Full Code Here


            int sign2 = val.isInfinity() ? val.infinitySign : val.value.signum();
            return newInfinity(runtime, sign1 * sign2);
        }

        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();
    }
View Full Code Here

        // TODO: no need to calculate every time.
        if (isZero()) {
            return 0;
        }
        BigDecimal val = value.abs().stripTrailingZeros();
        return val.precision() - val.scale();
    }

    @JRubyMethod(name = "sqrt", required = 1)
    public IRubyObject sqrt(IRubyObject arg) {
        Ruby runtime = getRuntime();
View Full Code Here

            bigDecimal = (BigDecimal) num;
        } else {
            bigDecimal = new BigDecimal(num.toString()).stripTrailingZeros();
        }

        int intLength = bigDecimal.precision() - bigDecimal.scale();
        if (integral >= intLength) {
            int factionLength = bigDecimal.scale() < 0 ? 0 : bigDecimal.scale();
            return fractional >= factionLength;
        } else {
            return false;
View Full Code Here

        }
        // Check overall
        if (type==DataType.DECIMAL)
        {   // Convert to Decimal
            BigDecimal dv = ObjectUtils.toDecimal(n);
            int prec = dv.precision();
            int scale = dv.scale();
            // check precision and scale
            double size = getSize();
            int reqPrec = (int)size;
            int reqScale =((int)(size*10)-(reqPrec*10));
 
View Full Code Here

            val = buffer.toString();
         }
         fixed_value = new BigDecimal( val );

         org.omg.CORBA.TypeCode type = orb.create_fixed_tc
             ((short) fixed_value.precision(), (short)fixed_value.scale());

         if ( type.fixed_digits() > type().fixed_digits() )
         {
            throw new InvalidValue();
         }
View Full Code Here

             val = sb.toString();
          }
          BigDecimal tmp = new BigDecimal( val );

          org.omg.CORBA.TypeCode tc = ORB.init().create_fixed_tc
              ((short)tmp.precision(), (short)tmp.scale());

          if ( tc.fixed_digits() > type.fixed_digits() )
          {
             throw new org.omg.CORBA.BAD_TYPECODE();
          }
View Full Code Here

    BigDecimal bigNum = getBigDecimalValue( str );
    if ( bigNum == null ) {
      return false;
    }

    int integerPartLength = bigNum.precision() - bigNum.scale();
    int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();

    return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
  }
View Full Code Here

    }
    else {
      bigNum = new BigDecimal( num.toString() ).stripTrailingZeros();
    }

    int integerPartLength = bigNum.precision() - bigNum.scale();
    int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();

    return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
  }
View Full Code Here

    BigDecimal bigNum = getBigDecimalValue( str );
    if ( bigNum == null ) {
      return false;
    }

    int integerPartLength = bigNum.precision() - bigNum.scale();
    int fractionPartLength = bigNum.scale() < 0 ? 0 : bigNum.scale();

    return ( maxIntegerLength >= integerPartLength && maxFractionLength >= fractionPartLength );
  }
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.