本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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)));
}
示例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);
}
示例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);
}
示例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);
}
示例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()]));
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
示例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;
}