Example usage for java.math BigDecimal abs

List of usage examples for java.math BigDecimal abs

Introduction

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

Prototype

public BigDecimal abs() 

Source Link

Document

Returns a BigDecimal whose value is the absolute value of this BigDecimal , and whose scale is this.scale() .

Usage

From source file:uk.ac.leeds.ccg.andyt.projects.fluvialglacial.SlopeAreaScatterPlot.java

private String getCoeff(BigDecimal coeffBD, String coeffS) {
    String result = "";
    if (coeffBD.compareTo(BigDecimal.ZERO) != 0) {
        if (coeffBD.compareTo(BigDecimal.ZERO) == 1) {
            result += coeffS;/* www .j  a v  a  2  s .c  o  m*/
        } else {
            result += "-" + coeffBD.abs().toPlainString();
        }
    }
    return result;
}

From source file:nl.strohalm.cyclos.entities.accounts.transactions.Transfer.java

/**
 * Returns the amount as a positive number, even when it's negative (i.e. chargeback)
 *//*from  w w w.  jav  a2 s .c o m*/
public BigDecimal getActualAmount() {
    final BigDecimal amount = getAmount();
    return amount == null ? null : amount.abs();
}

From source file:org.totschnig.myexpenses.activity.AccountEdit.java

/**
 * populates the input field either from the database or with default value for currency (from Locale)
 *///  w ww .  jav  a 2s  . c  o  m
private void populateFields() {

    BigDecimal amount = mAccount.openingBalance.getAmountMajor();
    if (amount.signum() == -1) {
        amount = amount.abs();
    } else {
        mType = INCOME;
        configureType();
    }
    mAmountText.setAmount(amount);
    mCurrencySpinner.setSelection(
            currencyAdapter.getPosition(CurrencyEnum.valueOf(mAccount.currency.getCurrencyCode())));
    mAccountTypeSpinner.setSelection(mAccount.type.ordinal());
    int selected = mColors.indexOf(mAccount.color);
    mColorSpinner.setSelection(selected);
}

From source file:com.rockagen.gnext.service.spring.AccountServImpl.java

/**
 * Account bill// w  w  w .  jav  a 2 s. c  om
 *
 * @param po     po
 * @param amount before balance
 * @param amount amount
 * @param remark remark
 */
private void genAccountBill(Account po, AccountOperationType opType, BigDecimal beforeBalance,
        BigDecimal amount, String remark) {
    // account bill
    Date now = new Date();
    AccountBill ab = new AccountBill();
    ab.setRemark(remark);
    ab.setAccount(po);
    ab.setAmount(amount.abs());
    ab.setCreatedAt(now);
    ab.setOperationType(opType);
    ab.setBeforeBalance(beforeBalance);
    ab.setAfterBalance(po.getBalance());
    ab.setSn(getBillSn(po.getUser().getId()));
    accountBillServ.add(ab);

}

From source file:nl.strohalm.cyclos.services.accounts.AccountTypeServiceImpl.java

private void fillSystemLimits(final AccountType accountType) {
    if (accountType instanceof SystemAccountType) {
        final SystemAccountType sat = (SystemAccountType) accountType;
        final SystemAccount account = sat.getAccount();
        if (account != null) {
            BigDecimal creditLimit = account.getCreditLimit();
            if (creditLimit != null) {
                sat.setCreditLimit(creditLimit.abs().negate());
            }//from  w w  w .j  av  a  2 s .co m
            sat.setUpperCreditLimit(account.getUpperCreditLimit());
        }
    }
}

From source file:com.autentia.tnt.manager.billing.BillManager.java

public void calculateBillIsPaid(final Bill bill) {
    if (bill.getState() != BillState.PAID) {
        BigDecimal accountEntryTotal = new BigDecimal(0);
        for (AccountEntry accountEntry : bill.getEntries()) {
            accountEntryTotal = accountEntryTotal.add(accountEntry.getAmount());
        }/*from w ww . j  a va 2 s . co  m*/
        if (accountEntryTotal.abs().compareTo(bill.getTotal()) >= 0) {
            bill.setState(BillState.PAID);
            updateEntity(bill);
        }
    }
}

From source file:org.openbravo.costing.CostingUtils.java

public static BigDecimal getDefaultCost(Product product, BigDecimal qty, Organization org, Date costDate,
        Date movementDate, BusinessPartner bp, Currency currency,
        HashMap<CostDimension, BaseOBObject> costDimensions) {
    Costing stdCost = getStandardCostDefinition(product, org, costDate, costDimensions);
    PriceList pricelist = null;/*from  w w  w. j ava2 s.c  o  m*/
    if (bp != null) {
        pricelist = bp.getPurchasePricelist();
    }
    ProductPrice pp = FinancialUtils.getProductPrice(product, movementDate, false, pricelist, false);
    if (stdCost == null && pp == null) {
        throw new OBException("@NoPriceListOrStandardCostForProduct@ @Organization@: " + org.getName()
                + ", @Product@: " + product.getName() + ", @Date@: " + OBDateUtils.formatDate(costDate));
    } else if (stdCost != null && pp == null) {
        BigDecimal standardCost = getStandardCost(product, org, costDate, costDimensions, currency);
        return qty.abs().multiply(standardCost);
    } else if (stdCost == null && pp != null) {
        BigDecimal cost = pp.getStandardPrice().multiply(qty.abs());
        if (DalUtil.getId(pp.getPriceListVersion().getPriceList().getCurrency()).equals(currency.getId())) {
            // no conversion needed
            return cost;
        }
        return FinancialUtils.getConvertedAmount(cost, pp.getPriceListVersion().getPriceList().getCurrency(),
                currency, movementDate, org, FinancialUtils.PRECISION_STANDARD);

    } else if (stdCost != null && pp != null
            && stdCost.getStartingDate().before(pp.getPriceListVersion().getValidFromDate())) {
        BigDecimal cost = pp.getStandardPrice().multiply(qty.abs());
        if (DalUtil.getId(pp.getPriceListVersion().getPriceList().getCurrency()).equals(currency.getId())) {
            // no conversion needed
            return cost;
        }
        return FinancialUtils.getConvertedAmount(cost, pp.getPriceListVersion().getPriceList().getCurrency(),
                currency, movementDate, org, FinancialUtils.PRECISION_STANDARD);
    } else {
        BigDecimal standardCost = getStandardCost(product, org, costDate, costDimensions, currency);
        return qty.abs().multiply(standardCost);
    }
}

From source file:org.yes.cart.service.domain.impl.SkuWarehouseServiceImpl.java

/**
 * {@inheritDoc}//from  w ww  .  j a  v a  2 s.co m
 */
@CacheEvict(value = { "skuWarehouseService-productOnWarehouse",
        "skuWarehouseService-productSkusOnWarehouse" }, allEntries = true)
public BigDecimal debit(final Warehouse warehouse, final String productSkuCode, final BigDecimal debitQty) {

    final SkuWarehouse skuWarehouse = findByWarehouseSkuForUpdate(warehouse, productSkuCode);

    if (skuWarehouse == null) {
        return debitQty.setScale(Constants.DEFAULT_SCALE);
    } else {
        BigDecimal canDebit = skuWarehouse.getQuantity().min(debitQty);
        BigDecimal rest = skuWarehouse.getQuantity().subtract(debitQty);
        skuWarehouse.setQuantity(skuWarehouse.getQuantity().subtract(canDebit));
        update(skuWarehouse);
        if (MoneyUtils.isFirstBiggerThanOrEqualToSecond(BigDecimal.ZERO, rest)) {
            return rest.abs().setScale(Constants.DEFAULT_SCALE);
        } else {
            return BigDecimal.ZERO.setScale(Constants.DEFAULT_SCALE);
        }
    }

}

From source file:org.gnucash.android.ui.transaction.SplitEditorFragment.java

/**
 * Extracts the input from the views and builds {@link org.gnucash.android.model.Split}s to correspond to the input.
 * @return List of {@link org.gnucash.android.model.Split}s represented in the view
 *//*from  w ww. j ava 2  s  .co m*/
private ArrayList<Split> extractSplitsFromView() {
    ArrayList<Split> splitList = new ArrayList<>();
    for (View splitView : mSplitItemViewList) {
        SplitViewHolder viewHolder = (SplitViewHolder) splitView.getTag();
        if (viewHolder.splitAmountEditText.getValue() == null)
            continue;

        BigDecimal amountBigDecimal = viewHolder.splitAmountEditText.getValue();

        String currencyCode = mAccountsDbAdapter.getCurrencyCode(mAccountUID);
        Money valueAmount = new Money(amountBigDecimal.abs(), Commodity.getInstance(currencyCode));

        String accountUID = mAccountsDbAdapter.getUID(viewHolder.accountsSpinner.getSelectedItemId());
        Split split = new Split(valueAmount, accountUID);
        split.setMemo(viewHolder.splitMemoEditText.getText().toString());
        split.setType(viewHolder.splitTypeSwitch.getTransactionType());
        split.setUID(viewHolder.splitUidTextView.getText().toString().trim());
        if (viewHolder.quantity != null)
            split.setQuantity(viewHolder.quantity.abs());
        splitList.add(split);
    }
    return splitList;
}

From source file:org.openbravo.advpaymentmngt.utility.FIN_Utility.java

public static BigDecimal getPaymentAmount(Boolean isReceipt, BigDecimal amount) {
    BigDecimal payment = BigDecimal.ZERO;
    if (isReceipt) {
        if (amount.compareTo(BigDecimal.ZERO) == -1) {
            // Negative payment in, treat as payment
            payment = amount.abs();
        }// w ww.j a v a2s . c om
    } else {
        if (amount.compareTo(BigDecimal.ZERO) == 1) {
            payment = amount;
        }
        // else sent payment was negative so treat as deposit
    }
    return payment;

}