Package java.math

Examples of java.math.BigDecimal.precision()


  public BigDecimal next() {
    BigInteger unscaled = new BigInteger(precision, rng);
    BigDecimal unscaledBD = new BigDecimal(unscaled);
    int scale =
        rng.nextInt(MAX_SCALE - MIN_SCALE + 1) + MIN_SCALE
            - unscaledBD.precision();
    BigDecimal result = new BigDecimal(unscaled, -scale);
    if (rng.nextBoolean()) {
      result = result.negate();
    }
    return result;
View Full Code Here


  static String stringFromBigDecimal( BigDecimal _value, Environment _environment )
  {
    if (_value.compareTo( BigDecimal.ZERO ) == 0) return "0"; // avoid "0.0"
    final BigDecimal stripped = _value.stripTrailingZeros();
    final int scale = stripped.scale();
    final int prec = stripped.precision();
    final int ints = prec - scale;
    if (ints > 20) {
      final DecimalFormatSymbols syms = getDecimalFormatSymbols( _environment );
      // Note: '.' is hard-coded in BigDecimal.toString().
      return stripped.toString().replace( '.', syms.getDecimalSeparator() );
View Full Code Here

      return "0"; // avoid "0.0"
    }

    final BigDecimal stripped = _value.stripTrailingZeros();
    final int scale = stripped.scale();
    final int precision = stripped.precision();
    final int integerDigits = precision - scale;
    if (integerDigits > _intDigitsLimitInt) {
      return formatExp( stripped, _environment );
    }
    if (scale > 9 && integerDigits <= 0 && _value.abs().compareTo( MAX_EXP_VALUE ) < 0) {
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

   * Test that constructing BigDecimals from zeros works properly.
   */
  public void testConstrZero() {
    BigDecimal bd = new BigDecimal("0");
    assertEquals(0, bd.intValueExact());
    assertEquals(1, bd.precision());
    assertEquals(0, bd.scale());
    bd = new BigDecimal("0.0");
    assertEquals(0, bd.intValueExact());
    assertEquals(1, bd.precision());
    assertEquals(1, bd.scale());
View Full Code Here

    assertEquals(0, bd.intValueExact());
    assertEquals(1, bd.precision());
    assertEquals(0, bd.scale());
    bd = new BigDecimal("0.0");
    assertEquals(0, bd.intValueExact());
    assertEquals(1, bd.precision());
    assertEquals(1, bd.scale());
    bd = new BigDecimal("0.00");
    assertEquals(0, bd.intValueExact());
    assertEquals(1, bd.precision());
    assertEquals(2, bd.scale());
View Full Code Here

    assertEquals(0, bd.intValueExact());
    assertEquals(1, bd.precision());
    assertEquals(1, bd.scale());
    bd = new BigDecimal("0.00");
    assertEquals(0, bd.intValueExact());
    assertEquals(1, bd.precision());
    assertEquals(2, bd.scale());
  }

  /**
   * check ONE.
View Full Code Here

  public void testRoundMathContextCEILING() {
    BigDecimal val = BigDecimal.valueOf(1.5);
    BigDecimal result = val.round(new MathContext(1, RoundingMode.CEILING));
    assertEquals("2", result.toString());
    assertEquals(0, result.scale());
    assertEquals(1, result.precision());
   
    // 1 digit left of dp, 14 scale + 1
    val = BigDecimal.valueOf(5.43445663479765);
    val =
        val.setScale(val.scale() + 1, RoundingMode.CEILING).round(new
View Full Code Here

   */
  public void testPrecision() {
    String a = "12312124789874829887348723648726347429808779810457634781384756794987";
    int aScale = 14;
    BigDecimal aNumber = new BigDecimal(new BigInteger(a), aScale);
    int prec = aNumber.precision();
    assertEquals(68, prec);
  }
}
View Full Code Here

    Decimal28SparseHolder dch = new Decimal28SparseHolder();

    BigDecimal bigDecimal = new BigDecimal(decimal);

    dch.scale = bigDecimal.scale();
    dch.precision = bigDecimal.precision();
    dch.setSign(bigDecimal.signum() == -1);
    dch.start = 0;

    dch.buffer = Unpooled.wrappedBuffer(new byte[5 * DecimalUtility.integerSize]);
    dch.buffer = new SwappedByteBuf(dch.buffer);
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.