java.math.BigDecimal.add()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(446)

本文整理了Java中java.math.BigDecimal.add()方法的一些代码示例,展示了BigDecimal.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BigDecimal.add()方法的具体详情如下:
包路径:java.math.BigDecimal
类名称:BigDecimal
方法名:add

BigDecimal.add介绍

[英]Returns a new BigDecimal whose value is this + augend. The scale of the result is the maximum of the scales of the two arguments.
[中]返回一个新的BigDecimal,其值为this+augend。结果的范围是两个参数范围的最大值。

代码示例

代码示例来源:origin: knowm/XChange

/**
 * Returns the total amount of the <code>currency</code> in this balance.
 *
 * @return the total amount.
 */
public BigDecimal getTotal() {
 if (total == null) {
  return available.add(frozen).subtract(borrowed).add(loaned).add(withdrawing).add(depositing);
 } else {
  return total;
 }
}

代码示例来源:origin: redisson/redisson

/**
 * Returns <code>BigDecimal</code> value of JD.
 */
@SuppressWarnings({"UnpredictableBigDecimalConstructorCall"})
public BigDecimal toBigDecimal() {
  BigDecimal bd = new BigDecimal(integer);
  return bd.add(new BigDecimal(fraction));
}

代码示例来源:origin: stackoverflow.com

BigDecimal _0_1 = new BigDecimal(0.1);
BigDecimal x = _0_1;
for(int i = 1; i <= 10; i ++) {
  System.out.println(i+" x 0.1 is "+x+", as double "+x.doubleValue());
  x = x.add(_0_1);
}

代码示例来源:origin: macrozheng/mall

private BigDecimal calcTotalAmount(List<CartPromotionItem> cartItemList) {
  BigDecimal total = new BigDecimal("0");
  for (CartPromotionItem item : cartItemList) {
    BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount());
    total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity())));
  }
  return total;
}

代码示例来源:origin: apache/nifi

public static void main(String[] args) throws Exception {
  BigDecimal totalDataSize = new BigDecimal("0.0");
  BigDecimal max = new BigDecimal("0.0");
  BigDecimal min = new BigDecimal("0.0");
  BigDecimal avg = new BigDecimal("0.0");
  long maxQueueSize       = 0L;
  InputStream gzipStream = new GZIPInputStream(fileStream);
  System.out.println("Using flow=" + input);
            ? convertSizeToByteValue(maxDataSize) : new BigDecimal("0.0");
        numberOfConnections++;
        avg = avg.add(byteValue);
        String dataQueueSize = maxWorkQueueSize.getElementsByTagName("maxWorkQueueSize").item(0)
            .getTextContent();
          min = byteValue;
        totalDataSize = totalDataSize.add(byteValue);

代码示例来源:origin: knowm/XChart

tickLabels.add(numberFormatter.format(BigDecimal.valueOf(maxValue).doubleValue()));
tickLocations.add(workingSpace / 2.0);
return;
BigDecimal gridStepBigDecimal = new BigDecimal(gridStep, MathContext.DECIMAL64);
 tickLabels.add(numberFormatter.format(BigDecimal.valueOf((maxValue + minValue) / 2.0)));
 tickLocations.add(workingSpace / 2.0);
 return;
} else if (firstPositionAsDouble == Double.NEGATIVE_INFINITY) {
 firstPosition = BigDecimal.valueOf(-1 * Double.MAX_VALUE);
} else {
 try {
 } catch (java.lang.NumberFormatException e) {
  System.out.println(
    "Some debug stuff. This happens once in a blue moon, and I don't know why.");
  System.out.println("scale: " + scale);
  System.out.println("exponent: " + exponent);
  System.out.println("gridStep: " + gridStep);
  System.out.println("cleanedGridStep: " + cleanedGridStep);
  value.compareTo(BigDecimal.valueOf(maxValue + 2 * cleanedGridStep.doubleValue())) < 0;
  value = value.add(cleanedGridStep)) {

代码示例来源:origin: stackoverflow.com

public class Payment
{
  BigDecimal itemCost  = BigDecimal.ZERO;
  BigDecimal totalCost = BigDecimal.ZERO;

  public BigDecimal calculateCost(int itemQuantity, BigDecimal itemPrice)
  {
    itemCost  = itemPrice.multiply(new BigDecimal(itemQuantity));
    totalCost = totalCost.add(itemCost);
    return totalCost;
  }
}

代码示例来源:origin: knowm/XChange

public BigDecimal getAveragePrice() {
 return low.add(high).divide(new BigDecimal("2"));
}

代码示例来源:origin: com.ning.billing/killbill-invoice

@Test(groups = "fast")
public void testDoubleProRation_TargetDateInSecondProRationPeriod() throws InvalidDateSequenceException {
  final LocalDate startDate = invoiceUtil.buildDate(2011, 1, 1);
  final LocalDate targetDate = invoiceUtil.buildDate(2012, 1, 17);
  final LocalDate endDate = invoiceUtil.buildDate(2012, 1, 27);
  BigDecimal expectedValue;
  expectedValue = FOURTEEN.divide(THREE_HUNDRED_AND_SIXTY_FIVE, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD);
  expectedValue = expectedValue.add(ONE);
  expectedValue = expectedValue.add(TWELVE.divide(THREE_HUNDRED_AND_SIXTY_SIX, 2 * NUMBER_OF_DECIMALS, ROUNDING_METHOD));
  expectedValue = expectedValue.setScale(NUMBER_OF_DECIMALS, ROUNDING_METHOD);
  testCalculateNumberOfBillingCycles(startDate, endDate, targetDate, 15, expectedValue);
}

代码示例来源:origin: prestodb/presto

@VisibleForTesting
public static BigDecimal average(LongDecimalWithOverflowAndLongState state, DecimalType type)
{
  BigDecimal sum = new BigDecimal(Decimals.decodeUnscaledValue(state.getLongDecimal()), type.getScale());
  BigDecimal count = BigDecimal.valueOf(state.getLong());
  if (state.getOverflow() != 0) {
    BigInteger overflowMultiplier = TWO.shiftLeft(UNSCALED_DECIMAL_128_SLICE_LENGTH * 8 - 2);
    BigInteger overflow = overflowMultiplier.multiply(BigInteger.valueOf(state.getOverflow()));
    sum = sum.add(new BigDecimal(overflow));
  }
  return sum.divide(count, type.getScale(), ROUND_HALF_UP);
}

代码示例来源:origin: debezium/debezium

public static Number add(BigInteger first, double second) {
  return new BigDecimal(first).add(BigDecimal.valueOf(second));
}

代码示例来源:origin: apache/hive

public BigDecimal randHiveBigDecimalNear(Random r, BigDecimal bigDecimal) {
 int scale = bigDecimal.scale();
 int delta = r.nextInt(10);
 if (r.nextBoolean()) {
  return bigDecimal.add(new BigDecimal(BigInteger.valueOf(delta), scale));
 } else {
  return bigDecimal.subtract(new BigDecimal(BigInteger.valueOf(delta), scale));
 }
}

代码示例来源:origin: embulk/embulk

private BigDecimal putFractionIfValid(final Map<String, Object> hash, final String key, final int value) {
  if (value != Integer.MIN_VALUE) {
    return (BigDecimal) hash.put(key, BigDecimal.ZERO.add(BigDecimal.valueOf(value, 9)));
  }
  return null;
}

代码示例来源:origin: pentaho/pentaho-kettle

@Override
public BigDecimal getBigNumber( Object object ) throws KettleValueException {
 Timestamp timestamp = getTimestamp( object );
 if ( timestamp == null ) {
  return null;
 }
 BigDecimal nanos =
   BigDecimal.valueOf( timestamp.getTime() ).multiply( BigDecimal.valueOf( 1000000000L ) ).add(
     BigDecimal.valueOf( timestamp.getNanos() ) );
 return nanos;
}

代码示例来源:origin: prestodb/presto

private static List<BigDecimal> toBigDecimalList(BigDecimal minValue, BigDecimal maxValue, List<Long> values)
  {
    return values.stream()
        .flatMap(value -> Stream.of(maxValue.subtract(BigDecimal.valueOf(value)), minValue.add(BigDecimal.valueOf(value))))
        .collect(toImmutableList());
  }
}

代码示例来源:origin: prestodb/presto

@Override
public SqlDecimal getExpectedValue(int start, int length)
{
  if (length == 0) {
    return null;
  }
  BigDecimal avg = BigDecimal.ZERO;
  for (int i = start; i < start + length; i++) {
    avg = avg.add(getBigDecimalForCounter(i));
  }
  avg = avg.divide(BigDecimal.valueOf(length), ROUND_HALF_UP);
  return new SqlDecimal(avg.unscaledValue(), avg.precision(), avg.scale());
}

代码示例来源:origin: knowm/XChange

totalValue = totalValue.add(trade.getCurrency1Amount().multiply(trade.getRate()));
totalQuantity = totalQuantity.add(trade.getCurrency1Amount());
totalFee = totalFee.add(trade.getCommissionPaid());
 totalValue.divide(totalQuantity, 8, BigDecimal.ROUND_HALF_UP);

代码示例来源:origin: knowm/XChange

public BigDecimal calcAsk() {
 return ask.add(BASIS_POINT_MULTIPLIER.multiply(askBP));
}

代码示例来源:origin: stackoverflow.com

BigDecimal test = new BigDecimal(0);
System.out.println(test);
test = test.add(new BigDecimal(30));
System.out.println(test);
test = test.add(new BigDecimal(45));
System.out.println(test);

代码示例来源:origin: macrozheng/mall

private BigDecimal calcTotalAmountByproductCategoryId(List<CartPromotionItem> cartItemList,List<Long> productCategoryIds) {
  BigDecimal total = new BigDecimal("0");
  for (CartPromotionItem item : cartItemList) {
    if(productCategoryIds.contains(item.getProductCategoryId())){
      BigDecimal realPrice = item.getPrice().subtract(item.getReduceAmount());
      total=total.add(realPrice.multiply(new BigDecimal(item.getQuantity())));
    }
  }
  return total;
}

相关文章