当前位置: 首页>>代码示例>>Java>>正文


Java BigDecimal.precision方法代码示例

本文整理汇总了Java中java.math.BigDecimal.precision方法的典型用法代码示例。如果您正苦于以下问题:Java BigDecimal.precision方法的具体用法?Java BigDecimal.precision怎么用?Java BigDecimal.precision使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.math.BigDecimal的用法示例。


在下文中一共展示了BigDecimal.precision方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: calculate

import java.math.BigDecimal; //导入方法依赖的package包/类
private static BigDecimal calculate(String input) {

        int i = 1;
        while (i < input.length() && !order.containsKey(input.charAt(i)))
            i++;

        String var = input.substring(0, i);
        BigDecimal value = variables.getOrDefault(var, new BigDecimal(var));

        char ope = i < input.length() ? input.charAt(0) : 0;
        if (ope == 0) return value;

        int currOrder = order.getOrDefault(ope, -1);

        BigDecimal result = null;
        if (currOrder > 0)
            result = calculate(input.substring(i + 1));

        switch (currOrder) {
            case '+':
                return value.add(result);
            case '-':
                return value.subtract(result);
            case '*':
                return value.multiply(result);
            case '/':
                return value.divide(result, BigDecimal.ROUND_HALF_UP);
            case '^':
                // If pow of int BigDecimal can handle it
                if (result.precision() == 0) return value.pow(result.intValue());
                // Otherwise we gotta revert to power of doubles
                return BigDecimal.valueOf(Math.pow(value.doubleValue(), result.doubleValue()));
        }

        return null;
    }
 
开发者ID:Baizey,项目名称:Helpers,代码行数:37,代码来源:Evaluator.java

示例2: deserializeBigDecimal

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Deserialize a Volt fixed precision and scale 16-byte decimal and return
 * it as a {@link java.math.BigDecimal BigDecimal} .
 * @param in {@link org.voltdb.messaging.FastDeserializer FastDeserializer} to read from
 * @throws IOException Thrown by <code>FastDeserializer</code>
 */
public static BigDecimal deserializeBigDecimal(FastDeserializer in)
    throws IOException
{
    byte decimalBytes[] = new byte[16];
    in.readFully(decimalBytes);
    if (java.util.Arrays.equals(decimalBytes, NULL_INDICATOR)) {
        return null;
    }
    final BigDecimal bd = new BigDecimal(new BigInteger(decimalBytes),
                    kDefaultScale, context);
    if (bd.precision() > 38) {
        throw new IOException("Decimal " + bd + " has precision > 38.");

    }
    return bd;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:23,代码来源:VoltDecimalHelper.java

示例3: precision

import java.math.BigDecimal; //导入方法依赖的package包/类
public static int precision(BigDecimal o) {

        if (o == null) {
            return 0;
        }

//#ifdef JAVA6
        return o.precision();

//#else
/*
        BigInteger big  = o.unscaledValue();
        int        sign = big.signum() == -1 ? 1
                                             : 0;

        return big.toString().length() - sign;
*/

//#endif JAVA6
    }
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:21,代码来源:JavaSystem.java

示例4: encodeBinary

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public final void encodeBinary(final BigDecimal value, final BufferWriter b) {
  final BigDecimal minimized = value.stripTrailingZeros();
  final BigInteger unscaled = minimized.abs().unscaledValue();
  final int sign = minimized.signum();

  final int beforeDecimal = minimized.precision() - minimized.scale();
  // the decimal point must align on a base-10000 digit
  final int padZeroes = 4 - minimized.scale() % 4;

  BigInteger paddedUnscaled;
  if (padZeroes == 0)
    paddedUnscaled = unscaled;
  else
    paddedUnscaled = unscaled.multiply(BigInteger.valueOf(10).pow(padZeroes));

  final short[] digits = findDigits(paddedUnscaled, EMPTY_SHORT_ARRAY);

  int weight;
  if (digits.length != 0) {
    int firstDigitSize;
    if (digits[0] < 10)
      firstDigitSize = 1;
    else if (digits[0] < 100)
      firstDigitSize = 2;
    else if (digits[0] < 1000)
      firstDigitSize = 3;
    else
      firstDigitSize = 4;
    weight = (beforeDecimal - firstDigitSize) / 4;
  } else
    weight = 0;

  b.writeShort((short) digits.length);
  b.writeShort((short) weight);
  b.writeShort(sign < 0 ? NUMERIC_NEG : NUMERIC_POS);
  b.writeShort((short) value.scale());
  for (final short digit : digits)
    b.writeShort(digit);
}
 
开发者ID:traneio,项目名称:ndbc,代码行数:41,代码来源:BigDecimalEncoding.java

示例5: deserializeBigDecimalFromString

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Deserialize a Volt fixed precision and scale 16-byte decimal from a String representation
 * @param decimal <code>String</code> representation of the decimal
 */
public static BigDecimal deserializeBigDecimalFromString(String decimal) throws IOException
{
    if (decimal == null) {
        return null;
    }
    final BigDecimal bd = new BigDecimal(decimal);
    if (bd.scale() > 12) {
        throw new IOException("Decimal " + bd + " has more then 12 digits of scale");
    }
    if (bd.precision() > 38) {
        throw new RuntimeException("Decimal " + bd + " has more than  38 digits of precision.");
    }
    return bd;
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:19,代码来源:VoltDecimalHelper.java

示例6: getDecimal28Holder

import java.math.BigDecimal; //导入方法依赖的package包/类
public static Decimal28SparseHolder getDecimal28Holder(DrillBuf buf, String decimal) {

    Decimal28SparseHolder dch = new Decimal28SparseHolder();

    BigDecimal bigDecimal = new BigDecimal(decimal);

    dch.scale = bigDecimal.scale();
    dch.precision = bigDecimal.precision();
    Decimal28SparseHolder.setSign(bigDecimal.signum() == -1, dch.start, dch.buffer);
    dch.start = 0;
    dch.buffer = buf.reallocIfNeeded(5 * DecimalUtility.integerSize);
    DecimalUtility.getSparseFromBigDecimal(bigDecimal, dch.buffer, dch.start, dch.scale, dch.precision, dch.nDecimalDigits);

    return dch;
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:16,代码来源:ValueHolderHelper.java

示例7: getDecimal38Holder

import java.math.BigDecimal; //导入方法依赖的package包/类
public static Decimal38SparseHolder getDecimal38Holder(DrillBuf buf, String decimal) {

      Decimal38SparseHolder dch = new Decimal38SparseHolder();

      BigDecimal bigDecimal = new BigDecimal(decimal);

      dch.scale = bigDecimal.scale();
      dch.precision = bigDecimal.precision();
      Decimal38SparseHolder.setSign(bigDecimal.signum() == -1, dch.start, dch.buffer);
      dch.start = 0;
      dch.buffer = buf.reallocIfNeeded(dch.maxPrecision * DecimalUtility.integerSize);
      DecimalUtility.getSparseFromBigDecimal(bigDecimal, dch.buffer, dch.start, dch.scale, dch.precision, dch.nDecimalDigits);

      return dch;
  }
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:16,代码来源:ValueHolderHelper.java

示例8: next

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
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;
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:14,代码来源:FloatGenerator.java

示例9: getScaledValue

import java.math.BigDecimal; //导入方法依赖的package包/类
private String getScaledValue(String valueStr, long decimals) {
    // Perform decimal conversion
    BigDecimal value = new BigDecimal(valueStr);
    value = value.divide(new BigDecimal(Math.pow(10, decimals)));
    int scale = 3 - value.precision() + value.scale();
    return value.setScale(scale, RoundingMode.HALF_UP).stripTrailingZeros().toPlainString();
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:8,代码来源:TransactionDetailActivity.java

示例10: parse

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Parses a price of type <code>String</code> and converts it to a
 * <code>BigDecimal</code>, considering the active locale. It accepts
 * maximum {@link #NUMBER_OF_INTEGER_PLACES} integer digits and
 * {@link #NUMBER_OF_DECIMAL_PLACES} decimal digits. It accepts grouping
 * separators according to the active locale, placed at any position in the
 * integer part, but not in the decimal part. It accepts no <code>+</code>
 * symbol and no currency symbols (like <code>€</code> or <code>$</code>).
 * Also, If <code>allosNegativePrice</code> is <code>true</code>, negative
 * price is not accepted.
 * 
 * @param price
 *            The price to be parsed as <code>String</code>. May be
 *            <code>null</code>, otherwise it will be trimmed.
 * @param allosNegativePrice
 *            Defined if negative price value is allowed or not. If value is
 *            <code>true</code>, negative price is not accepted.
 * @return The parsed <code>BigDecimal</code> representing the
 *         <code>price</code>. Returns <code>BigDecimal.ZERO</code> if the
 *         given <code>price</code> parameter is <code>null</code> or it
 *         contains no characters other then blanks.
 * @throws ParseException
 *             if the specified <code>price</code> string represents no
 *             valid price as described.
 */
public BigDecimal parse(String price, boolean allowNegativePrice)
        throws ParseException {
    if (price == null || price.trim().length() == 0) {
        return BigDecimal.ZERO;
    }
    BigDecimal bigDecimal = VALIDATOR.validate(price,
            FORMAT_PATTERN_WITH_GROUPING, getActiveLocale());
    if (bigDecimal == null) {
        throw new ParseException("Invalid price: " + price, 0);
    } else if (bigDecimal.compareTo(BigDecimal.ZERO) < 0
            && !allowNegativePrice) {
        // used compareTo() to ignore the scale
        throw new ParseException("Negative price: " + price, 0);
    }
    if (bigDecimal.scale() > NUMBER_OF_DECIMAL_PLACES
            || (bigDecimal.precision() - bigDecimal.scale()) > NUMBER_OF_INTEGER_PLACES) {
        throw new ParseException(
                "ERROR_PRICEMODEL_INVALID_FRACTIONAL_PART", 0);
    }
    return bigDecimal;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:47,代码来源:PriceConverter.java

示例11: Decimal9Expression

import java.math.BigDecimal; //导入方法依赖的package包/类
public Decimal9Expression(BigDecimal input, ExpressionPosition pos) {
  super(pos);
  this.scale = input.scale();
  this.precision = input.precision();
  this.decimal = CoreDecimalUtility.getDecimal9FromBigDecimal(input, scale, precision);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:7,代码来源:ValueExpressions.java

示例12: Decimal18Expression

import java.math.BigDecimal; //导入方法依赖的package包/类
public Decimal18Expression(BigDecimal input, ExpressionPosition pos) {
  super(pos);
  this.scale = input.scale();
  this.precision = input.precision();
  this.decimal = CoreDecimalUtility.getDecimal18FromBigDecimal(input, scale, precision);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:7,代码来源:ValueExpressions.java

示例13: weiToEth

import java.math.BigDecimal; //导入方法依赖的package包/类
public static BigDecimal weiToEth(BigInteger wei, int sigFig) throws Exception {
    BigDecimal eth = weiToEth(wei);
    int scale = sigFig - eth.precision() + eth.scale();
    return eth.setScale(scale, RoundingMode.HALF_UP);
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:6,代码来源:BalanceUtils.java

示例14: DecimalExpression

import java.math.BigDecimal; //导入方法依赖的package包/类
public DecimalExpression(BigDecimal input) {
  this.scale = input.scale();
  this.precision = input.precision();
  this.decimal = CoreDecimalUtility.getDecimal9FromBigDecimal(input, scale, precision);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:6,代码来源:ValueExpressions.java


注:本文中的java.math.BigDecimal.precision方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。