List of usage examples for java.math BigDecimal multiply
public BigDecimal multiply(BigDecimal multiplicand)
(this × multiplicand)
, and whose scale is (this.scale() + multiplicand.scale()) . From source file:com.silverpeas.util.MetadataExtractor.java
private void computeMp4Duration(Metadata metadata, MovieHeaderBox movieHeaderBox) { BigDecimal duration = BigDecimal.valueOf(movieHeaderBox.getDuration()); if (duration.intValue() > 0) { BigDecimal divisor = BigDecimal.valueOf(movieHeaderBox.getTimescale()); // Duration duration = duration.divide(divisor, 10, BigDecimal.ROUND_HALF_DOWN); // get duration in ms duration = duration.multiply(BigDecimal.valueOf(1000)); metadata.add(XMPDM.DURATION, duration.toString()); }//from w w w. j av a2 s. c o m }
From source file:com.benfante.minimark.blo.ResultCalculationBo.java
/** * Evaluate an assessment normalizing the sum of the marks of each question * to a maximum value./*from ww w . jav a2 s.c o m*/ * * @param assessment The assessment to evaluate. * @param maxValue The maximum value to wich normalize. If it's null, the default is 100. * @return The evaluation */ public BigDecimal calculateNormalizedSum(AssessmentFilling assessment, BigDecimal maxValue) { if (maxValue == null) { maxValue = new BigDecimal("100.00"); } BigDecimal result = new BigDecimal("0.00"); for (QuestionFilling questionFilling : assessment.getQuestions()) { result = addQuestionMarkedWeight(questionFilling, result); } final BigDecimal totalWeight = assessment.getTotalWeight(); if (!BigDecimal.ZERO.equals(totalWeight)) { result = result.multiply(maxValue).divide(totalWeight, 2, RoundingMode.HALF_EVEN); } return result; }
From source file:jgnash.ui.report.compiled.PayeePieChart.java
private PieDataset[] createPieDataSet(final Account a) { DefaultPieDataset[] returnValue = new DefaultPieDataset[2]; returnValue[0] = new DefaultPieDataset(); returnValue[1] = new DefaultPieDataset(); if (a != null) { //System.out.print("Account = "); System.out.println(a); Map<String, BigDecimal> names = new HashMap<>(); List<TranTuple> list = getTransactions(a, new ArrayList<>(), startField.getLocalDate(), endField.getLocalDate()); CurrencyNode currency = a.getCurrencyNode(); for (final TranTuple tranTuple : list) { Transaction tran = tranTuple.transaction; Account account = tranTuple.account; String payee = tran.getPayee(); BigDecimal sum = tran.getAmount(account); sum = sum.multiply(account.getCurrencyNode().getExchangeRate(currency)); //System.out.print(" Transaction = "); System.out.print(payee); System.out.print(" "); System.out.println(sum); if (useFilters.isSelected()) { for (String aFilterList : filterList) { PayeeMatcher pm = new PayeeMatcher(aFilterList, false); if (pm.matches(tran)) { payee = aFilterList; //System.out.println(filterList.get(i)); break; }//from w ww . j a v a 2 s .c om } } if (names.containsKey(payee)) { sum = sum.add(names.get(payee)); } names.put(payee, sum); } for (final Map.Entry<String, BigDecimal> entry : names.entrySet()) { BigDecimal value = entry.getValue(); if (value.compareTo(BigDecimal.ZERO) == -1) { value = value.negate(); returnValue[1].setValue(entry.getKey(), value); } else { returnValue[0].setValue(entry.getKey(), value); } } } return returnValue; }
From source file:edu.zipcloud.cloudstreetmarket.api.controllers.UsersController.java
private void prepareUserForUpdate(User user) { User existingUser = communityService.findOne(user.getId()); if (!existingUser.getCurrency().equals(user.getCurrency())) { CurrencyExchange currencyExchange = currencyExchangeService .gather(existingUser.getCurrency().name() + user.getCurrency().name() + "=X"); BigDecimal change = BigDecimal.valueOf(1L); if (currencyExchange != null && currencyExchange.getAsk() != null && currencyExchange.getAsk().compareTo(BigDecimal.ZERO) > 0) { change = currencyExchange.getAsk(); }/*from ww w. ja v a2 s . c om*/ //Let's say 2.5% virtual charge applied for now user.setBalance(change.multiply(existingUser.getBalance()).multiply(BigDecimal.valueOf(0.975))); } else { user.setBalance(existingUser.getBalance()); } }
From source file:com.envision.envservice.service.RankingListService.java
private List<SpiritSortBo> sortuserPraiseNumSort(Map<String, Integer> lowerUserPraiseNum, final SortType sortType) { List<SpiritSortBo> sbos = new ArrayList<SpiritSortBo>(); for (Entry<String, Integer> entry : lowerUserPraiseNum.entrySet()) { if (!TOTAL.equals(entry.getKey())) { SpiritSortBo sbo = new SpiritSortBo(); sbo.setUserId(entry.getKey()); BigDecimal fz = new BigDecimal(entry.getValue()); BigDecimal fm = new BigDecimal(lowerUserPraiseNum.get(TOTAL)); if (fm.intValue() == 0) { sbo.setPercent("0"); } else { DecimalFormat df = new DecimalFormat("0.00"); String pe = df.format(fz.multiply(new BigDecimal(100)).divide(fm, 2, RoundingMode.HALF_UP)); sbo.setPercent(pe);//from w w w . j a v a 2s. c o m } sbos.add(sbo); } } // ? // Collections.sort(sbos, new SpiritSortBoComparator(sortType)); Collections.sort(sbos, new Comparator<SpiritSortBo>() { public int compare(SpiritSortBo o1, SpiritSortBo o2) { BigDecimal o1Percent = new BigDecimal(o1.getPercent()); BigDecimal o2Percent = new BigDecimal(o2.getPercent()); int multiplier = -1; if (sortType.equals(SortType.ASC)) { multiplier = 1; } return o1Percent.compareTo(o2Percent) * multiplier; } }); return sbos; }
From source file:module.siadap.domain.SiadapEvaluationUniverse.java
private BigDecimal getPonderationResult(BigDecimal scoring, int usedPercentage) { BigDecimal percentage = BigDecimal.valueOf(usedPercentage).divide(new BigDecimal(100)); BigDecimal result = percentage.multiply(scoring); return result.setScale(PRECISION, ROUND_MODE); }
From source file:cpcc.core.base.PolygonZone.java
/** * @return the coordinates of the center of gravity. *///from w w w. j a va 2 s . c om public PolarCoordinate getCenterOfGravity() { BigDecimal x = new BigDecimal(0), y = new BigDecimal(0); BigDecimal doubleArea = new BigDecimal(0); for (int k = 0, l = vertices.length - 1; k < l; ++k) { BigDecimal ax = new BigDecimal(vertices[k].x); BigDecimal ay = new BigDecimal(vertices[k].y); BigDecimal bx = new BigDecimal(vertices[k + 1].x); BigDecimal by = new BigDecimal(vertices[k + 1].y); BigDecimal t = ax.multiply(by).subtract(bx.multiply(ay)); x = x.add(ax.add(bx).multiply(t)); y = y.add(ay.add(by).multiply(t)); doubleArea = doubleArea.add(ax.multiply(by).subtract(bx.multiply(ay))); } double sixTimesArea = 3.0 * doubleArea.doubleValue(); return new PolarCoordinate(x.doubleValue() / sixTimesArea, y.doubleValue() / sixTimesArea, 0); }
From source file:org.kuali.kpme.tklm.leave.payout.service.LeavePayoutServiceImpl.java
@Override public LeavePayout initializePayout(String principalId, String accrualCategoryRule, BigDecimal accruedBalance, LocalDate effectiveDate) { //Initially, principals may be allowed to edit the transfer amount when prompted to submit this balance transfer, however, //a base transfer amount together with a forfeited amount is calculated to bring the balance back to its limit in accordance //with transfer limits. LeavePayout leavePayout = null;// ww w .j a va 2 s . c om AccrualCategoryRule accrualRule = HrServiceLocator.getAccrualCategoryRuleService() .getAccrualCategoryRule(accrualCategoryRule); if (ObjectUtils.isNotNull(accrualRule) && ObjectUtils.isNotNull(accruedBalance)) { leavePayout = new LeavePayout(); //Leave summary is not a requirement, per se, but the information it contains is. //The only thing that is obtained from leave summary is the accrued balance of the leave summary row matching the //passed accrualCategoryRules accrual category. //These two objects are essential to balance transfers triggered when the employee submits their leave calendar for approval. //Neither of these objects should be null, otherwise this method could not have been called. AccrualCategory fromAccrualCategory = HrServiceLocator.getAccrualCategoryService() .getAccrualCategory(accrualRule.getLmAccrualCategoryId()); BigDecimal fullTimeEngagement = HrServiceLocator.getJobService() .getFteSumForAllActiveLeaveEligibleJobs(principalId, effectiveDate); // AccrualRule.maxBalance == null -> no balance limit. No balance limit -> no accrual triggered transfer / payout / lose. // execution point should not be here if max balance on accrualRule is null, unless there exists an employee override. BigDecimal maxBalance = accrualRule.getMaxBalance(); BigDecimal adjustedMaxBalance = maxBalance.multiply(fullTimeEngagement).setScale(2); BigDecimal maxPayoutAmount = null; BigDecimal adjustedMaxPayoutAmount = null; if (ObjectUtils.isNotNull(accrualRule.getMaxPayoutAmount())) { maxPayoutAmount = new BigDecimal(accrualRule.getMaxPayoutAmount()); adjustedMaxPayoutAmount = maxPayoutAmount.multiply(fullTimeEngagement).setScale(2); } else { // no limit on transfer amount maxPayoutAmount = new BigDecimal(Long.MAX_VALUE); adjustedMaxPayoutAmount = maxPayoutAmount; } BigDecimal maxCarryOver = null; BigDecimal adjustedMaxCarryOver = null; if (ObjectUtils.isNotNull(accrualRule.getMaxCarryOver())) { maxCarryOver = new BigDecimal(accrualRule.getMaxCarryOver()); adjustedMaxCarryOver = maxCarryOver.multiply(fullTimeEngagement).setScale(2); } else { //no limit to carry over. maxCarryOver = new BigDecimal(Long.MAX_VALUE); adjustedMaxCarryOver = maxCarryOver; } EmployeeOverrideContract maxBalanceOverride = LmServiceLocator.getEmployeeOverrideService() .getEmployeeOverride(principalId, fromAccrualCategory.getLeavePlan(), fromAccrualCategory.getAccrualCategory(), "MB", effectiveDate); EmployeeOverrideContract maxPayoutAmountOverride = LmServiceLocator.getEmployeeOverrideService() .getEmployeeOverride(principalId, fromAccrualCategory.getLeavePlan(), fromAccrualCategory.getAccrualCategory(), "MPA", effectiveDate); EmployeeOverrideContract maxAnnualCarryOverOverride = LmServiceLocator.getEmployeeOverrideService() .getEmployeeOverride(principalId, fromAccrualCategory.getLeavePlan(), fromAccrualCategory.getAccrualCategory(), "MAC", effectiveDate); //Do not pro-rate override values for FTE. if (maxBalanceOverride != null) adjustedMaxBalance = new BigDecimal(maxBalanceOverride.getOverrideValue()); if (maxPayoutAmountOverride != null) adjustedMaxPayoutAmount = new BigDecimal(maxPayoutAmountOverride.getOverrideValue()); if (maxAnnualCarryOverOverride != null) adjustedMaxCarryOver = new BigDecimal(maxAnnualCarryOverOverride.getOverrideValue()); BigDecimal transferAmount = accruedBalance.subtract(adjustedMaxBalance); if (transferAmount.compareTo(adjustedMaxPayoutAmount) > 0) { //there's forfeiture. //bring transfer amount down to the adjusted maximum transfer amount, and place excess in forfeiture. //accruedBalance - adjustedMaxPayoutAmount - adjustedMaxBalance = forfeiture. //transferAmount = accruedBalance - adjustedMaxBalance; forfeiture = transferAmount - adjustedMaxPayoutAmount. BigDecimal forfeiture = transferAmount.subtract(adjustedMaxPayoutAmount).setScale(2); forfeiture = forfeiture.stripTrailingZeros(); leavePayout.setForfeitedAmount(forfeiture); leavePayout.setPayoutAmount(adjustedMaxPayoutAmount); } else { leavePayout.setPayoutAmount(transferAmount); leavePayout.setForfeitedAmount(BigDecimal.ZERO); } assert (adjustedMaxBalance.compareTo(accruedBalance .subtract(leavePayout.getPayoutAmount().add(leavePayout.getForfeitedAmount()))) == 0); // Max Carry Over logic for Year End transfers. if (StringUtils.equals(accrualRule.getMaxBalanceActionFrequency(), HrConstants.MAX_BAL_ACTION_FREQ.YEAR_END)) { if (ObjectUtils.isNotNull(maxCarryOver)) { if (ObjectUtils.isNull(adjustedMaxCarryOver)) adjustedMaxCarryOver = maxCarryOver.multiply(fullTimeEngagement).setScale(2); //otherwise, adjustedMaxCarryOver has an employee override value, which trumps accrual rule defined MAC. //At this point, transfer amount and forfeiture have been set so that the new accrued balance will be the //adjusted max balance, so this amount is used to check against carry over. if (adjustedMaxBalance.compareTo(adjustedMaxCarryOver) > 0) { BigDecimal carryOverDiff = adjustedMaxBalance.subtract(adjustedMaxCarryOver); if (StringUtils.equals(accrualRule.getActionAtMaxBalance(), HrConstants.ACTION_AT_MAX_BALANCE.LOSE)) { //add carry over excess to forfeiture. leavePayout.setForfeitedAmount(leavePayout.getForfeitedAmount().add(carryOverDiff)); } else { //maximize the transfer amount. BigDecimal potentialPayoutAmount = leavePayout.getPayoutAmount().add(carryOverDiff); //Can this entire amount be added to the transfer amount?? if (potentialPayoutAmount.compareTo(adjustedMaxPayoutAmount) <= 0) { //yes leavePayout.setPayoutAmount(leavePayout.getPayoutAmount().add(carryOverDiff)); } else { //no BigDecimal carryOverExcess = potentialPayoutAmount .subtract(adjustedMaxPayoutAmount); //move excess to forfeiture leavePayout .setForfeitedAmount(leavePayout.getForfeitedAmount().add(carryOverExcess)); //the remainder (if any) can be added to the transfer amount ( unless action is LOSE ). leavePayout.setPayoutAmount( leavePayout.getPayoutAmount().add(carryOverDiff.subtract(carryOverExcess))); assert (adjustedMaxCarryOver.compareTo(accruedBalance.subtract( leavePayout.getPayoutAmount().add(leavePayout.getForfeitedAmount()))) == 0); } } } //otherwise, given balance will be at or under the max annual carry over. } } leavePayout.setEffectiveLocalDate(effectiveDate); leavePayout.setAccrualCategoryRule(accrualCategoryRule); leavePayout.setFromAccrualCategory(fromAccrualCategory.getAccrualCategory()); leavePayout.setPrincipalId(principalId); leavePayout.setUserPrincipalId(HrContext.getPrincipalId()); leavePayout.setEarnCode(accrualRule.getMaxPayoutEarnCode()); } return leavePayout; }
From source file:eu.bittrade.libs.steemj.protocol.Asset.java
/** * Set the amount of this asset.//from ww w.jav a2s . c om * * @param amount * The amount. */ public void setAmount(BigDecimal amount) { if (amount.scale() > this.getPrecision()) { throw new InvalidParameterException("The provided 'amount' has a 'scale' of " + amount.scale() + ", but needs to have a 'scale' of " + this.getPrecision() + " when " + this.getSymbol().name() + " is used as a AssetSymbolType."); } this.amount = amount.multiply(BigDecimal.valueOf(Math.pow(10, this.getPrecision()))).longValue(); }
From source file:com.konakart.bl.modules.ordertotal.thomson.ThomsonCustomBase.java
public void adjustOrderAfterTaxCalculation(StaticData sd, TaxCalculationResponse response, OrderIf order) { if (response.getOUTDATA().getINVOICE() != null && response.getOUTDATA().getINVOICE().get(0) != null && response.getOUTDATA().getINVOICE().get(0).getLINE() != null) { /*// w w w . jav a 2 s . c o m * for (OutdataLineType line : response.getOUTDATA().getINVOICE().get(0).getLINE()) { if * (line.getCOMMODITYCODE() != null && * line.getCOMMODITYCODE().equals("FREIGHT INCLUSIVE")) { if * (!Utils.isBlank(line.getTOTALTAXAMOUNT())) { if (log.isDebugEnabled()) { * log.debug("Thomson Tax reduced by " + line.getTOTALTAXAMOUNT() + * " for VAT-inclusive Shipping"); } adjustedTaxAmountBD = * adjustedTaxAmountBD.subtract(new BigDecimal(line .getTOTALTAXAMOUNT())); } } } */ // For each line reset the tax and priceIncTax on the OrderProducts & ShippingQuote int lineNum = 0; for (OutdataLineType line : response.getOUTDATA().getINVOICE().get(0).getLINE()) { lineNum++; if (line.getDESCRIPTION() != null) { BigDecimal taxBD = new BigDecimal(line.getTOTALTAXAMOUNT()); if (line.getDESCRIPTION().equals("Shipping Charge")) { if (!Utils.isBlank(line.getTOTALTAXAMOUNT())) { order.getShippingQuote().setTax(taxBD); order.getShippingQuote() .setTotalExTax(order.getShippingQuote().getTotalIncTax().subtract(taxBD)); } } else { order.getOrderProducts()[lineNum - 1].setTax(taxBD); order.getOrderProducts()[lineNum - 1].setFinalPriceIncTax( order.getOrderProducts()[lineNum - 1].getFinalPriceExTax().add(taxBD)); if (line.getTAXSUMMARY() != null && line.getTAXSUMMARY().getTAXRATE() != null) { BigDecimal taxRateBD = new BigDecimal(line.getTAXSUMMARY().getTAXRATE()); order.getOrderProducts()[lineNum - 1] .setTaxRate(taxRateBD.multiply(new BigDecimal("100"))); } } } } } }