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


Java BigDecimal.add方法代码示例

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


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

示例1: testBigDecimals

import java.math.BigDecimal; //导入方法依赖的package包/类
public void testBigDecimals() throws IOException
    {
        BigDecimal bigBase = new BigDecimal("1234567890344656736.125");
        final BigDecimal[] input = new BigDecimal[] {
                // 04-Jun-2017, tatu: these look like integral numbers in JSON so can't use:
//                BigDecimal.ZERO,
//                BigDecimal.ONE,
//                BigDecimal.TEN,
                BigDecimal.valueOf(-999.25),
                bigBase,
                bigBase.divide(new BigDecimal("5")),
                bigBase.add(bigBase),
                bigBase.multiply(new BigDecimal("1.23")),
                bigBase.negate()
        };
        ByteArrayOutputStream bytes = new ByteArrayOutputStream(100);
        JsonFactory f = JSON_F;
        JsonGenerator g = f.createGenerator(ObjectWriteContext.empty(), bytes);
        g.writeStartArray();
        for (int i = 0; i < input.length; ++i) {
            g.writeNumber(input[i]);
        }
        g.writeEndArray();
        g.close();
        byte[] data = bytes.toByteArray();

        _testBigDecimals(f, input, data, 0, 100);
        _testBigDecimals(f, input, data, 0, 3);
        _testBigDecimals(f, input, data, 0, 1);

        _testBigDecimals(f, input, data, 1, 100);
        _testBigDecimals(f, input, data, 2, 3);
        _testBigDecimals(f, input, data, 3, 1);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:AsyncScalarArrayTest.java

示例2: getAllocatedQuantityForDemandItem

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal getAllocatedQuantityForDemandItem(String id, Long oId, Long mId) {
  BigDecimal alq = new BigDecimal(0);
  try {
    InventoryManagementService
        ims =
        Services.getService(InventoryManagementServiceImpl.class);
    OrderManagementService oms = Services.getService(OrderManagementServiceImpl.class);
    IOrder o = oms.getOrder(oId);
    Long lkId = o.getServicingKiosk();
    List<IInvAllocation>
        iAllocs =
        ims.getAllocationsByTypeId(lkId, mId, IInvAllocation.Type.ORDER, oId.toString());
    if (iAllocs != null && !iAllocs.isEmpty()) {
      for (IInvAllocation iAlloc : iAllocs) {
        alq = alq.add(iAlloc.getQuantity());
      }
    }
  } catch (Exception e) {
    xLogger.warn("Exception while getting allocated quantity for the demand item {0}, order: {1}",
        id, oId, e);
  }
  return alq;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:25,代码来源:DemandService.java

示例3: sumCorrelationsOfBucket

import java.math.BigDecimal; //导入方法依赖的package包/类
static BigDecimal sumCorrelationsOfBucket(RiskClass riskClass, List<WeightedSensitivity> weightedSensitivities) {
  BigDecimal sum = BigDecimal.ZERO;

  for (WeightedSensitivity weightedSensitivityK : weightedSensitivities) {
    for (WeightedSensitivity weightedSensitivityI : weightedSensitivities) {
      if (!weightedSensitivityI.equals(weightedSensitivityK)) {
        BigDecimal concentrationRisk = RiskConcentration.getDeltaIntraBucketCorrelation(riskClass, weightedSensitivityI, weightedSensitivityK, weightedSensitivities);
        BigDecimal correlation = RiskCorrelation.getSensitivityCorrelation(riskClass, weightedSensitivityI.getSensitivity(), weightedSensitivityK.getSensitivity());
        BigDecimal value = concentrationRisk.multiply(correlation).multiply(weightedSensitivityI.getWeightedValue()).multiply(weightedSensitivityK.getWeightedValue());
        sum = sum.add(value);
      }
    }
  }

  return sum;
}
 
开发者ID:AcadiaSoft,项目名称:simm-lib,代码行数:17,代码来源:DeltaMarginBucketUtils.java

示例4: avg

import java.math.BigDecimal; //导入方法依赖的package包/类
public static IEnumerable avg(IEnumerable source) throws Exception
{
	IEnumerator en = source.enumerator();
	if (!en.moveNext())
	{
		en.close();
		return new MFEmptySequence();
	}
	
	BigDecimal acc = (BigDecimal) en.current();
	int cnt = 1;
	while (en.moveNext())
	{
		acc = acc.add((BigDecimal)en.current());
		++cnt;
	}
	en.close();
	return new MFSingletonSequence(Core.divide(acc, BigDecimal.valueOf(cnt)));
}
 
开发者ID:CenPC434,项目名称:java-tools,代码行数:20,代码来源:Core.java

示例5: computeTransactionIntoRightCurrencyRate

import java.math.BigDecimal; //导入方法依赖的package包/类
protected BigDecimal computeTransactionIntoRightCurrencyRate(List<Transaction> transactions,
                                                         String toCurrency, GraphDomain graphDomain,
                                                         List<TransactionRatedDomain> transactionRatedDomainList)
        throws CustomException {
    BigDecimal totalAmount = new BigDecimal(BIG_DEC_0F);
    for (Transaction transaction : transactions) {
        BigDecimal currency = new BigDecimal(BIG_DEC_1F);
        if (graphDomain != null) {
            currency = graphDomain.searchCurrency(transaction.getCurrency(), toCurrency);
        }
        BigDecimal amountSpentInitially = new BigDecimal(transaction.getAmountPerTransaction());
        TransactionRatedDomain transactionRatedDomain = new TransactionRatedDomain(transaction.getCurrency(),
                mToCurrency,
                RoundingUtil.round(amountSpentInitially, ROUND_TO),
                RoundingUtil.round(amountSpentInitially.multiply(currency), ROUND_TO));
        transactionRatedDomainList.add(transactionRatedDomain);
        totalAmount = totalAmount.add(transactionRatedDomain.getAmountPerTransactionCurrent());
    }
    return RoundingUtil.round(totalAmount, ROUND_TO);
}
 
开发者ID:raulh82vlc,项目名称:Transactions-Viewer,代码行数:21,代码来源:ComputeTransactionsInteractorImpl.java

示例6: calculateCurvatureMarginResidual

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * As defined in Appendix 1 of ISDA_SIMM_2.0_(PUBLIC).pdf
 */
static BigDecimal calculateCurvatureMarginResidual(List<BucketWeightedAggregation> aggregateByBucket) {
  List<BucketWeightedAggregation> residuals = BucketWeightedAggregationUtils.filterOutNonResiduals(aggregateByBucket);
  BigDecimal sum = ZERO;
  for (BucketWeightedAggregation bucketWeightedAggregation : residuals) {
    BigDecimal weightedSensitivitiesSum = WeightedSensitivityUtils.sumWeightSensitivities(bucketWeightedAggregation.getWeightedSensitivities());
    BigDecimal calculateLambda = CurvatureMarginLambdaUtils.calculateLambda(bucketWeightedAggregation.getWeightedSensitivities());
    BigDecimal product = calculateLambda.multiply(bucketWeightedAggregation.getAggregate());
    BigDecimal riskFactorTotal = weightedSensitivitiesSum.add(product);
    sum = sum.add(riskFactorTotal);
  }
  return sum.max(ZERO);
}
 
开发者ID:AcadiaSoft,项目名称:simm-lib,代码行数:16,代码来源:CurvatureMarginResidualUtils.java

示例7: calculate

import java.math.BigDecimal; //导入方法依赖的package包/类
public void calculate() {
    BigDecimal currencyRevenue = BigDecimal.ZERO;
    BigDecimal totalCurrencyRevenue = BigDecimal.ZERO;
    for (Supplier supplier : getSupplier()) {
        supplier.calculate();
        currencyRevenue = currencyRevenue.add(supplier
                .getBrokerRevenuePerSupplier().getAmount());
        totalCurrencyRevenue = totalCurrencyRevenue.add(supplier
                .getBrokerRevenuePerSupplier().getTotalAmount());
    }
    currencyRevenue = currencyRevenue.setScale(
            PriceConverter.NORMALIZED_PRICE_SCALING,
            PriceConverter.ROUNDING_MODE);
    brokerRevenue.setAmount(currencyRevenue);
    totalCurrencyRevenue = totalCurrencyRevenue.setScale(
            PriceConverter.NORMALIZED_PRICE_SCALING,
            PriceConverter.ROUNDING_MODE);
    brokerRevenue.setTotalAmount(totalCurrencyRevenue);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:Currency.java

示例8: processMatched

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Process a MatchResult. A MatchResult contains one or more MatchRecords,
 * which reference to the same taker.
 * 
 * @param matchResult
 *            MatchResult object.
 */
public void processMatched(MatchResultMessage matchResult) {
	final long timestamp = matchResult.timestamp;
	// insert will failed if already processed:
	MatchResult mr = new MatchResult();
	mr.type = MatchResultType.MATCHED;
	mr.orderId = matchResult.orderId;
	db.save(mr);
	// a match result contains one taker and one or more makers:
	Order takerOrder = null;
	List<MatchRecord> recordCollector = new ArrayList<>();
	BigDecimal totalSpent = BigDecimal.ZERO;
	BigDecimal totalAmount = BigDecimal.ZERO;
	for (MatchRecordMessage record : matchResult.getMatchRecords()) {
		BigDecimal price = record.matchPrice;
		BigDecimal amount = record.matchAmount;
		if (takerOrder == null) {
			takerOrder = db.get(Order.class, record.takerOrderId);
		}
		Order makerOrder = db.get(Order.class, record.makerOrderId);
		clearMakerOrder(takerOrder, makerOrder, price, amount, record.makerStatus, timestamp, recordCollector);
		totalSpent = totalSpent.add(price.multiply(amount));
		totalAmount = totalAmount.add(amount);
	}
	clearTakerOrder(takerOrder, matchResult.takerStatus, totalSpent, totalAmount, timestamp);
	// batch insert:
	db.save(recordCollector.toArray(new MatchRecord[recordCollector.size()]));
}
 
开发者ID:michaelliao,项目名称:cryptoexchange,代码行数:35,代码来源:ClearingHandlerService.java

示例9: calculateFVForSwitchPlan

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * Means all current fund capitals are converted to Tuleva.
 */
protected FutureValue calculateFVForSwitchPlan(ComparisonCommand in) {
    int yearsToWork = in.ageOfRetirement - in.age;

    BigDecimal currentCapitals = BigDecimal.ZERO;
    for (Map.Entry<String, BigDecimal> entry : in.getCurrentCapitals().entrySet()) {
        String isin = entry.getKey();
        BigDecimal currentCapital = in.getCurrentCapitals().get(isin);

        if (currentCapital == null) {
            throw new RuntimeException("Missing current capital for fund " + isin);
        }
        currentCapitals = currentCapitals.add(currentCapital);
    }

    BigDecimal fundManagementFee = in.getManagementFeeRates().get(in.isinTo);
    BigDecimal effectiveManagementFee = in.isTulevaMember ? fundManagementFee.subtract(in.getTulevaMemberBonus()) : fundManagementFee;
    BigDecimal annualInterestRate = in.getReturnRate().subtract(effectiveManagementFee);
    BigDecimal capitalFv = fvCompoundInterest(currentCapitals, annualInterestRate, yearsToWork);
    BigDecimal capitalFvWithoutFee = fvCompoundInterest(currentCapitals, in.getReturnRate(), yearsToWork);
    BigDecimal yearlyContribution = in.monthlyWage.multiply(new BigDecimal(12)).multiply(in.secondPillarContributionRate);
    BigDecimal annuityFv = fvGrowingAnnuity(yearlyContribution, annualInterestRate, in.annualSalaryGainRate, yearsToWork);
    BigDecimal annuityFvWithoutFee = fvGrowingAnnuity(yearlyContribution, in.getReturnRate(), in.annualSalaryGainRate, yearsToWork);

    return FutureValue.builder()
            .withFee(capitalFv.add(annuityFv))
            .withoutFee(capitalFvWithoutFee.add(annuityFvWithoutFee))
            .build();
}
 
开发者ID:TulevaEE,项目名称:onboarding-service,代码行数:32,代码来源:ComparisonService.java

示例10: MathAdd

import java.math.BigDecimal; //导入方法依赖的package包/类
/**
 * @param int m
 * @param int n
 * Set current object to m+n
 */	
public MathAdd(int m, int n)
{
	m_d = new BigDecimal(String.valueOf(m));
	
	BigDecimal val2 = new BigDecimal(String.valueOf(n));
	m_d = m_d.add(val2); 
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:13,代码来源:MathAdd.java

示例11: calculatePiactivevb

import java.math.BigDecimal; //导入方法依赖的package包/类
private static BigDecimal calculatePiactivevb(BigInteger steps) {
    BigDecimal pi = BigDecimal.ZERO;
    for(BigInteger i = BigInteger.ONE; i.compareTo(steps) == -1; i.add(BigInteger.ONE)) {
        pi.add(BigDecimal.ONE.divide(new BigDecimal(i.toString()).pow(2)));
    }
    pi.multiply(new BigDecimal("6"));
    pi = JBigNumber.sqrt(pi, pi.scale());
    return pi;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:10,代码来源:Pi.java

示例12: getWeights

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public List<BigDecimal> getWeights() {

    final List<BigDecimal> retVal = new ArrayList<>();

    final BigDecimal tmpTotalWeight = this.getTotalWeight();

    BigDecimal tmpSum = BigMath.ZERO;
    BigDecimal tmpLargest = BigMath.ZERO;
    int tmpIndexOfLargest = -1;

    final List<BigDecimal> tmpWeights = myBasePortfolio.getWeights();
    BigDecimal tmpWeight;
    for (int i = 0; i < tmpWeights.size(); i++) {

        tmpWeight = tmpWeights.get(i);
        tmpWeight = DIVIDE.invoke(tmpWeight, tmpTotalWeight);
        tmpWeight = myWeightsContext.enforce(tmpWeight);

        retVal.add(tmpWeight);

        tmpSum = tmpSum.add(tmpWeight);

        if (tmpWeight.abs().compareTo(tmpLargest) == 1) {
            tmpLargest = tmpWeight.abs();
            tmpIndexOfLargest = i;
        }
    }

    if ((tmpSum.compareTo(BigMath.ONE) != 0) && (tmpIndexOfLargest != -1)) {
        retVal.set(tmpIndexOfLargest, retVal.get(tmpIndexOfLargest).subtract(tmpSum.subtract(BigMath.ONE)));
    }

    return retVal;
}
 
开发者ID:optimatika,项目名称:ojAlgo-finance,代码行数:36,代码来源:NormalisedPortfolio.java

示例13: doPost

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String idCommande = req.getParameter("id");
	Commande commande = commandeService.get(Integer.parseInt(idCommande));
	
	Integer clientId = Integer.parseInt(req.getParameter("clientId"));
	Integer livreurId = Integer.parseInt(req.getParameter("livreurId"));
	Statut statut = Statut.valueOf(req.getParameter("statut"));
	List<Pizza> pizzas = new ArrayList<>();
	String[] parameterValues = req.getParameterValues("pizzas");
	BigDecimal total = new BigDecimal(0);
	for(String id : parameterValues){
		Pizza pizza = pizzaService.get(Integer.parseInt(id));
		pizzas.add(pizza);
		total = total.add(pizza.getPrix());
	}
	
	commande.setClientId(clientService.retrieveClient(clientId));
	commande.setLivreurId(livreurService.get(livreurId));
	commande.setPizzas(pizzas);
	commande.setTotal(total);
	commande.setStatut(statut);
	
	commandeService.update(commande, Integer.parseInt(idCommande));
	
	
	resp.sendRedirect(req.getContextPath() + LIST_CONTROLLER);
	
}
 
开发者ID:DTAFormation,项目名称:112016.pizzeria-app,代码行数:30,代码来源:EditerCommandeController.java

示例14: ordersIdDelete

import java.math.BigDecimal; //导入方法依赖的package包/类
@Transactional
public OrderUpdate ordersIdDelete(Long id, DailyMenuDetails dailyMenuDetails, Long reqUserId) throws ApiException {

    com.jrtechnologies.yum.data.entity.User sourceUser = userRep
            .findById((Long) SecurityContextHolder.getContext().getAuthentication().getPrincipal());
    com.jrtechnologies.yum.data.entity.User user = getUserOfDailyOrder(sourceUser, reqUserId);

    //  Validation for daily order
    com.jrtechnologies.yum.data.entity.DailyOrder dailyOrderEntity = dailyOrderRep.findByDailyOrderId(id);

    // check if there is no order with this id 
    ConcurrentOrderDeletionCheck(dailyMenuDetails.getDailyMenuId(), dailyMenuDetails.getDailyMenuVersion(),
            dailyMenuDetails.getDailyMenuDate(), user, dailyOrderEntity);

    com.jrtechnologies.yum.data.entity.DailyMenu dailyMenuEntity = dailyOrderEntity.getDailyMenu();
    //  Validation for user, dailyMenu 
    if ((dailyMenuEntity == null) || user.getId() != dailyOrderEntity.getUserId()) {
        throw new ApiException(400, "Order couldn't be deleted.");
        // Check for deadline             
    } else if (deadlinePassed(dailyOrderEntity.getDailyMenu().getDate())
            && !allowAdminAfterTodayChangeOrder(sourceUser, dailyMenuEntity.getDate(), reqUserId)) {
        dailyOrderEntity.setFinalised(true);
        throw new ApiException(412, "Deadline for orders passed");
    } else {
        BigDecimal orderAmount = new BigDecimal(0);
        for (com.jrtechnologies.yum.data.entity.OrderItem orderItem : dailyOrderEntity.getOrderItems()) {
            orderAmount = orderAmount
                    .add(orderItem.getFood().getPrice().multiply(new BigDecimal(orderItem.getQuantity())));
        }

        BigDecimal balance = user.getBalance();
        if (balance == null) {
            balance = orderAmount;
        } else {
            balance = balance.add(orderAmount);
        }
        user.setBalance(balance);
        OrderUpdate orderUpdate = new OrderUpdate();
        orderUpdate.setBalance(balance);

        Transaction transaction = new Transaction(user.getId(), orderAmount, balance, sourceUser.getId(),
                dailyOrderEntity.getDailyOrderId(), dailyMenuEntity.getId(), 3);
        transactionRep.save(transaction);
        dailyOrderRep.delete(dailyOrderEntity);
        return orderUpdate;
    }
}
 
开发者ID:jrtechnologies,项目名称:yum,代码行数:48,代码来源:OrdersService.java

示例15: getCommissionRate

import java.math.BigDecimal; //导入方法依赖的package包/类
@Override
public BigDecimal getCommissionRate(Key key) {

    Optional<BitmexTick> tick = queryTick(key);

    BigDecimal rate = null;

    if (tick.isPresent()) {

        BigDecimal maker = tick.map(BitmexTick::getMakerFee).orElse(ZERO).max(ZERO);

        BigDecimal clear = tick.map(BitmexTick::getSettleFee).orElse(ZERO).max(ZERO);

        rate = maker.add(clear);

    }

    return rate;

}
 
开发者ID:after-the-sunrise,项目名称:cryptotrader,代码行数:21,代码来源:BitmexContext.java


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