Example usage for java.math BigDecimal setScale

List of usage examples for java.math BigDecimal setScale

Introduction

In this page you can find the example usage for java.math BigDecimal setScale.

Prototype

public BigDecimal setScale(int newScale) 

Source Link

Document

Returns a BigDecimal whose scale is the specified value, and whose value is numerically equal to this BigDecimal 's.

Usage

From source file:com.aimluck.eip.project.ProjectTaskSimpleSelectData.java

/**
 * ResultData???? <BR>/* ww w.j av a2  s .  c  o m*/
 * 
 * @param record
 *          
 * @return ResultData
 */
@Override
protected Object getResultData(EipTProjectTask record) {
    ProjectTaskResultData data = ProjectUtils.getProjectTaskResultData(record);
    Integer taskId = (int) data.getTaskId().getValue();

    // ?
    int cntChild = ProjectUtils.getCountChildrenTask(taskId);

    // ??2??true
    // ??
    data.setHasChildren(cntChild >= 2);

    // ?
    data.setHasChildrenForForm(cntChild > 0);

    // ?
    int lapsedDays = ProjectUtils.getLapsedDays(ProjectUtils.toString(record.getStartPlanDate()),
            ProjectUtils.toString(Calendar.getInstance().getTime()));
    // 
    int taskDays = ProjectUtils.getLapsedDays(ProjectUtils.toString(record.getStartPlanDate()),
            ProjectUtils.toString(record.getEndPlanDate()));
    data.setPlanTerm(taskDays);

    if (lapsedDays > taskDays) {
        // ???
        lapsedDays = taskDays;
    }

    // ?
    data.setPlanProgressRate(ProjectUtils.getPlanWorkload(lapsedDays, taskDays));

    // 
    List<ProjectTaskMemberResultData> memberList = data.getMemberList();
    BigDecimal workload = BigDecimal.valueOf(0);
    workload = workload.setScale(1);
    for (int i = 0; i < memberList.size(); i++) {
        ProjectTaskMemberResultData member = memberList.get(i);
        workload = workload.add(member.getWorkload());
    }
    data.setWorkload(workload);

    // 
    BigDecimal forecastWorkload = BigDecimal.valueOf(0);
    if (data.getProgressRate().getValue() != 0) {
        forecastWorkload = workload.multiply(BigDecimal.valueOf(100))
                .divide(BigDecimal.valueOf(data.getProgressRate().getValue()), 2, BigDecimal.ROUND_HALF_UP);
    }
    data.setForecastWorkload(forecastWorkload);

    // 
    data.setIndentFlg(indentFlg);

    return data;
}

From source file:org.key2gym.business.services.OrdersServiceBean.java

@Override
public BigDecimal getTotalForDate(DateMidnight date) throws SecurityViolationException {

    if (date == null) {
        throw new NullPointerException("The date is null."); //NOI18N
    }//from  w w w .  j  a  va  2 s .com

    if (!DateMidnight.now().equals(date) && !callerHasRole(SecurityRoles.MANAGER)) {
        throw new SecurityViolationException(getString("Security.Access.Denied"));
    }

    BigDecimal result = (BigDecimal) em.createNamedQuery("OrderEntity.sumPaymentsForDateRecorded") //NOI18N
            .setParameter("dateRecorded", date.toDate()) //NOI18N
            .getSingleResult();

    if (result == null) {
        result = BigDecimal.ZERO;
    }

    return result.setScale(2);
}

From source file:com.devnexus.ting.web.controller.RegisterController.java

private Payment runPayPal(RegistrationDetails registerForm, String serverBaseUrl) {
    final PayPalSession payPalSession = payPalSession();

    Amount amount = new Amount();
    amount.setCurrency("USD");
    final BigDecimal total = getTotal(registerForm);

    Transaction transaction = new Transaction();
    transaction.setDescription("DevNexus Registration");
    transaction.setAmount(amount);// w w w.j a va  2 s.c o m

    ItemList itemlist = new ItemList();
    List<Item> items = new ArrayList<>(registerForm.getOrderDetails().size());
    for (TicketOrderDetail order : registerForm.getOrderDetails()) {
        items.add(new Item("1",
                String.format("Registration for %s %s", order.getFirstName(), order.getLastName()),
                getOrderPrice(order).setScale(2).toString(), "USD"));
    }
    itemlist.setItems(items);

    amount.setTotal(total.setScale(2).toString());
    List<Transaction> transactions = new ArrayList<Transaction>();
    transactions.add(transaction);
    transaction.setItemList(itemlist);
    Payer payer = new Payer();
    payer.setPaymentMethod("paypal");

    Payment payment = new Payment();
    payment.setIntent("sale");
    payment.setPayer(payer);
    payment.setTransactions(transactions);
    RedirectUrls redirectUrls = new RedirectUrls();
    redirectUrls.setCancelUrl(serverBaseUrl + "/s/registerPageTwo/" + registerForm.getRegistrationFormKey());
    redirectUrls
            .setReturnUrl(serverBaseUrl + "/s/executeRegistration/" + registerForm.getRegistrationFormKey());
    payment.setRedirectUrls(redirectUrls);

    return payPalSession.createPayment(payment);
}

From source file:com.aimluck.eip.project.ProjectTaskSelectData.java

/**
 * ResultData???? <BR>/* w  ww.  j  a  va2 s. com*/
 *
 * @param record
 *          
 * @return ResultData
 */
@Override
protected Object getResultData(EipTProjectTask record) {
    ProjectTaskResultData data = ProjectUtils.getProjectTaskResultData(record);
    Integer taskId = (int) data.getTaskId().getValue();

    // ?
    int cntChild = ProjectUtils.getCountChildrenTask(taskId);

    // ??2??true
    // ??
    data.setHasChildren(cntChild >= 2);

    // ?
    data.setHasChildrenForForm(cntChild > 0);

    // ?
    int lapsedDays = ProjectUtils.getLapsedDays(ProjectUtils.toString(record.getStartPlanDate()),
            ProjectUtils.toString(Calendar.getInstance().getTime()));
    // 
    int taskDays = ProjectUtils.getLapsedDays(ProjectUtils.toString(record.getStartPlanDate()),
            ProjectUtils.toString(record.getEndPlanDate()));
    data.setPlanTerm(taskDays);

    if (lapsedDays > taskDays) {
        // ???
        lapsedDays = taskDays;
    }

    // ?
    data.setPlanProgressRate(ProjectUtils.getPlanWorkload(lapsedDays, taskDays));

    // 
    List<ProjectTaskMemberResultData> memberList = data.getMemberList();
    BigDecimal workload = BigDecimal.valueOf(0);
    workload = workload.setScale(1);
    for (int i = 0; i < memberList.size(); i++) {
        ProjectTaskMemberResultData member = memberList.get(i);
        workload = workload.add(member.getWorkload());
    }
    data.setWorkload(workload);

    // 
    BigDecimal forecastWorkload = BigDecimal.valueOf(0);
    if (data.getProgressRate().getValue() != 0) {
        forecastWorkload = workload.multiply(BigDecimal.valueOf(100))
                .divide(BigDecimal.valueOf(data.getProgressRate().getValue()), 2, BigDecimal.ROUND_HALF_UP);
    }
    data.setForecastWorkload(forecastWorkload);

    // 
    data.setIndentFlg(indentFlg);

    data.setEditable(ProjectFormUtils.isEditable(taskId, loginUserId));

    return data;
}

From source file:org.libreplan.web.orders.ManageOrderElementAdvancesModel.java

@Override
@Transactional(readOnly = true)//from   w  w w.j  av  a 2s  .c  om
public XYModel getChartData(Set<AdvanceAssignment> selectedAdvances) {
    XYModel xyModel = new SimpleXYModel();

    for (AdvanceAssignment each : selectedAdvances) {
        DirectAdvanceAssignment directAdvanceAssignment;
        if (each instanceof DirectAdvanceAssignment) {
            directAdvanceAssignment = (DirectAdvanceAssignment) each;
        } else {
            directAdvanceAssignment = calculateFakeDirectAdvanceAssignment((IndirectAdvanceAssignment) each);
        }
        if (directAdvanceAssignment != null) {
            String title = getInfoAdvanceAssignment(directAdvanceAssignment);
            SortedSet<AdvanceMeasurement> listAdvanceMeasurements = directAdvanceAssignment
                    .getAdvanceMeasurements();
            if (listAdvanceMeasurements.size() > 1) {
                for (AdvanceMeasurement advanceMeasurement : listAdvanceMeasurements) {
                    BigDecimal value = advanceMeasurement.getValue();
                    if ((selectedAdvances.size() > 1) && (value != null)
                            && (value.compareTo(BigDecimal.ZERO) > 0)) {
                        BigDecimal maxValue = directAdvanceAssignment.getMaxValue();
                        value = value.setScale(2).divide(maxValue, RoundingMode.DOWN);
                    }
                    LocalDate date = advanceMeasurement.getDate();
                    if ((value != null) && (date != null)) {
                        xyModel.addValue(title, date.toDateTimeAtStartOfDay().getMillis(), value);
                    }
                }
            }
        }
    }

    return xyModel;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.administrativeOffice.scholarship.utl.report.StudentLine.java

public Boolean getStudentHadPerformanceLastYear() {
    BigDecimal numberOfApprovedEctsOneYearAgo = getNumberOfApprovedEctsOneYearAgo();
    BigDecimal numberOfEnrolledEctsOneYearAgo = getNumberOfEnrolledEctsOneYearAgo();

    if (numberOfEnrolledEctsOneYearAgo.compareTo(BigDecimal.ZERO) == 0) {
        return false;
    }/* ww w . j a  v a2 s.co  m*/

    BigDecimal average = numberOfApprovedEctsOneYearAgo.divide(numberOfEnrolledEctsOneYearAgo,
            RoundingMode.HALF_EVEN);
    average.setScale(2);

    return average.compareTo(new BigDecimal(0.5f)) >= 0;
}

From source file:dk.clanie.bitcoin.client.BitcoindClientImpl.java

/**
 * Sets transaction fee.//from ww  w.j  av  a  2 s.c  om
 *
 * @param amount - transaction fee.
 * @return {@link BooleanResponse}
 */
@Override
public BooleanResponse setTxFee(BigDecimal amount) {
    List<Object> params = newArrayList();
    params.add(amount.setScale(SCALE));
    return jsonRpc("settxfee", params, BooleanResponse.class);
}

From source file:dk.clanie.bitcoin.client.BitcoindClientImpl.java

/**
 * Sends bitcoins to the given address./*from  ww w .  j  a v  a 2s  . c o m*/
 * 
 * @param address
 *            - bitcoin address
 * @param amount
 *            - bitcoins
 * @param comment
 *            - optional (may be null). Text for the transactions comment field
 * @param commentTo
 *            - optional (may be null). Text for the transactions to: field
 * @return String with transaction number
 */
@Override
public StringResponse sendToAddress(String address, BigDecimal amount, String comment, String commentTo) {
    List<Object> params = newArrayList();
    params.add(address);
    params.add(amount.setScale(SCALE));
    if (comment != null || commentTo != null)
        params.add(comment);
    if (commentTo != null)
        params.add(commentTo);
    return jsonRpc("sendtoaddress", params, StringResponse.class);
}

From source file:org.apache.phoenix.jdbc.PhoenixResultSet.java

@Override
public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException {
    BigDecimal value = getBigDecimal(columnIndex);
    return value.setScale(scale);
}

From source file:com.axelor.apps.account.service.payment.PayboxService.java

/**
 * Procdure permettant de raliser un paiement avec Paybox
 * @param paymentVoucher//from w  ww . j a  v a  2  s.com
 *             Une saisie paiement
 * @throws AxelorException
 * @throws UnsupportedEncodingException
 */
public String paybox(PaymentVoucher paymentVoucher) throws AxelorException, UnsupportedEncodingException {

    this.checkPayboxPaymentVoucherFields(paymentVoucher);

    Company company = paymentVoucher.getCompany();

    BigDecimal paidAmount = paymentVoucher.getPaidAmount();
    Partner payerPartner = paymentVoucher.getPartner();
    //      this.checkPayboxPartnerFields(payerPartner);
    this.checkPaidAmount(payerPartner, company, paidAmount);
    this.checkPaidAmount(paymentVoucher);

    PayboxConfig payboxConfig = payboxConfigService.getPayboxConfig(company);

    // Vrification du remplissage du chemin de la cl publique Paybox
    payboxConfigService.getPayboxPublicKeyPath(payboxConfig);

    String payboxUrl = payboxConfigService.getPayboxUrl(payboxConfig);
    String pbxSite = payboxConfigService.getPayboxSite(payboxConfig);
    String pbxRang = payboxConfigService.getPayboxRang(payboxConfig);
    String pbxDevise = payboxConfigService.getPayboxDevise(payboxConfig);
    String pbxTotal = paidAmount.setScale(2).toString().replace(".", "");
    String pbxCmd = paymentVoucher.getRef(); // Identifiant de la saisie paiement
    String pbxPorteur = this.getPartnerEmail(paymentVoucher);
    String pbxRetour = payboxConfigService.getPayboxRetour(payboxConfig);
    //      String pbxEffectue = this.encodeUrl(this.replaceVariableInUrl(accountConfigService.getPayboxRetourUrlEffectue(accountConfig), paymentVoucher));
    String pbxEffectue = this.replaceVariableInUrl(payboxConfigService.getPayboxRetourUrlEffectue(payboxConfig),
            paymentVoucher);
    String pbxRefuse = this.replaceVariableInUrl(payboxConfigService.getPayboxRetourUrlRefuse(payboxConfig),
            paymentVoucher);
    String pbxAnnule = this.replaceVariableInUrl(payboxConfigService.getPayboxRetourUrlAnnule(payboxConfig),
            paymentVoucher);
    String pbxIdentifiant = payboxConfigService.getPayboxIdentifiant(payboxConfig);
    String pbxHash = payboxConfigService.getPayboxHashSelect(payboxConfig);
    String pbxHmac = payboxConfigService.getPayboxHmac(payboxConfig);

    //Date  laquelle l'empreinte HMAC a t calcule (format ISO8601)
    String pbxTime = ISODateTimeFormat.dateHourMinuteSecond().print(new DateTime());

    // Permet de restreindre les modes de paiement
    String pbxTypepaiement = "CARTE";
    String pbxTypecarte = "CB";

    String message = this.buildMessage(pbxSite, pbxRang, pbxIdentifiant, pbxTotal, pbxDevise, pbxCmd,
            pbxPorteur, pbxRetour, pbxEffectue, pbxRefuse, pbxAnnule, pbxHash, pbxTime, pbxTypepaiement,
            pbxTypecarte);

    log.debug("Message : {}", message);

    String messageHmac = this.getHmacSignature(message, pbxHmac, pbxHash);

    log.debug("Message HMAC : {}", messageHmac);

    String messageEncode = this.buildMessage(URLEncoder.encode(pbxSite, this.CHARSET),
            URLEncoder.encode(pbxRang, this.CHARSET), URLEncoder.encode(pbxIdentifiant, this.CHARSET), pbxTotal,
            URLEncoder.encode(pbxDevise, this.CHARSET), URLEncoder.encode(pbxCmd, this.CHARSET),
            URLEncoder.encode(pbxPorteur, this.CHARSET), URLEncoder.encode(pbxRetour, this.CHARSET),
            URLEncoder.encode(pbxEffectue, this.CHARSET), URLEncoder.encode(pbxRefuse, this.CHARSET),
            URLEncoder.encode(pbxAnnule, this.CHARSET), URLEncoder.encode(pbxHash, this.CHARSET),
            URLEncoder.encode(pbxTime, this.CHARSET), URLEncoder.encode(pbxTypepaiement, this.CHARSET),
            URLEncoder.encode(pbxTypecarte, this.CHARSET));

    String url = payboxUrl + messageEncode + "&PBX_HMAC=" + messageHmac;

    log.debug("Url : {}", url);

    return url;
}