Example usage for java.math MathContext DECIMAL128

List of usage examples for java.math MathContext DECIMAL128

Introduction

In this page you can find the example usage for java.math MathContext DECIMAL128.

Prototype

MathContext DECIMAL128

To view the source code for java.math MathContext DECIMAL128.

Click Source Link

Document

A MathContext object with a precision setting matching the IEEE 754R Decimal128 format, 34 digits, and a rounding mode of RoundingMode#HALF_EVEN HALF_EVEN , the IEEE 754R default.

Usage

From source file:org.openconcerto.erp.core.supplychain.stock.element.StockItemsUpdater.java

/**
 * Rcupre les stocks associs aux articles non composs et les met  jour
 * // w ww  . jav  a 2  s.c om
 * @return la liste des stocks  jour
 */
private List<StockItem> fetch() {
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    List<StockItem> stockItems = new ArrayList<StockItem>(items.size());
    StockItem.Type stockItemType = this.type.isVirtual() ? StockItem.Type.THEORIQUE : StockItem.Type.REEL;
    for (SQLRowAccessor item : items) {

        if (!item.isForeignEmpty("ID_ARTICLE")) {
            SQLRowAccessor article = item.getForeign("ID_ARTICLE");

            // FIXME Create FIELD COMPOSED
            // if (!article.getBoolean("COMPOSED") && article.getBoolean("GESTION_STOCK")) {
            if (article.getBoolean("GESTION_STOCK")) {
                StockItem stockItem = new StockItem(article);

                final int qte = item.getInt("QTE");
                final BigDecimal qteUV = item.getBigDecimal("QTE_UNITAIRE");
                double qteFinal = qteUV.multiply(new BigDecimal(qte), MathContext.DECIMAL128).doubleValue();
                if (!this.type.isEntry()) {
                    qteFinal = -qteFinal;
                }
                stockItem.updateQty(qteFinal, stockItemType);
                stockItems.add(stockItem);
                if (this.createMouvementStock) {
                    String mvtStockQuery = "INSERT INTO "
                            + article.getTable().getTable("MOUVEMENT_STOCK").getSQLName().quote()
                            + " (\"QTE\",\"DATE\",\"ID_ARTICLE\",\"SOURCE\",\"IDSOURCE\",\"NOM\",\"REEL\") VALUES("
                            + qteFinal + ",'" + dateFormat.format(this.rowSource.getDate("DATE").getTime())
                            + "'," + article.getID() + ",'" + this.rowSource.getTable().getName() + "',"
                            + this.rowSource.getID() + ",'" + this.label.getLabel(this.rowSource, item) + "',"
                            + String.valueOf(!this.type.isVirtual()) + ")";
                    this.requests.add(mvtStockQuery);
                }
            }
        }
    }
    return stockItems;
}

From source file:org.openconcerto.erp.graph.GraphArticleMargePanel.java

@Override
protected void updateDataset(List<String> labels, List<Number> values) {

    final SQLTable tableVFElement = Configuration.getInstance().getDirectory()
            .getElement("SAISIE_VENTE_FACTURE_ELEMENT").getTable();

    final SQLSelect sel = new SQLSelect(tableVFElement.getBase());
    final String field = "NOM";

    sel.addSelect(tableVFElement.getField(field));

    sel.addSelect(tableVFElement.getField("PA_HT"));
    sel.addSelect(tableVFElement.getField("PV_HT"));
    sel.addSelect(tableVFElement.getField("QTE"), "SUM");

    final List<Object[]> rowsArticle = (List<Object[]>) Configuration.getInstance().getBase().getDataSource()
            .execute(sel.asString() + " GROUP BY \"SAISIE_VENTE_FACTURE_ELEMENT\".\"" + field + "\""
                    + ",\"SAISIE_VENTE_FACTURE_ELEMENT\".\"PA_HT\""
                    + ",\"SAISIE_VENTE_FACTURE_ELEMENT\".\"PV_HT\"", new ArrayListHandler());

    Collections.sort(rowsArticle, new Comparator<Object[]>() {
        @Override/*  w  w  w  .j av a 2 s  . com*/
        public int compare(Object[] o1, Object[] o2) {

            BigDecimal pa1 = (BigDecimal) o1[1];
            BigDecimal pv1 = (BigDecimal) o1[2];
            BigDecimal qte1 = new BigDecimal(o1[3].toString());

            BigDecimal pa2 = (BigDecimal) o2[1];
            BigDecimal pv2 = (BigDecimal) o2[2];
            BigDecimal qte2 = new BigDecimal(o2[3].toString());

            BigDecimal marge1 = pv1.subtract(pa1).multiply(qte1, MathContext.DECIMAL128);
            BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, MathContext.DECIMAL128);
            return marge1.compareTo(marge2);
        }
    });

    for (int i = 0; i < 10 && i < rowsArticle.size(); i++) {
        Object[] o = rowsArticle.get(i);
        BigDecimal pa2 = (BigDecimal) o[1];
        BigDecimal pv2 = (BigDecimal) o[2];
        BigDecimal qte2 = new BigDecimal(o[3].toString());
        BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, MathContext.DECIMAL128);

        final String string = o[0].toString();
        values.add(marge2);
        labels.add(string);
    }

}

From source file:org.openvpms.component.system.common.jxpath.BigDecimalOperationDivide.java

@Override
public Object computeValue(EvalContext context) {
    BigDecimal l = TypeConversionUtil.bigDecimalValue(args[0].computeValue(context));
    BigDecimal r = TypeConversionUtil.bigDecimalValue(args[1].computeValue(context));
    return l.divide(r, MathContext.DECIMAL128);
}

From source file:org.openvpms.component.system.common.jxpath.BigDecimalTestCase.java

/**
 * Verifies that BigDecimals are used to divide one value by another.
 *//*ww  w.j  ava 2s.co m*/
@Test
public void testDivide() {
    BigDecimal value = (BigDecimal) context.getValue("1 div 3");
    BigDecimal expected = new BigDecimal(1).divide(new BigDecimal(3), MathContext.DECIMAL128);
    checkEquals(expected, value);
}

From source file:ru.runa.wfe.extension.handler.var.FormulaActionHandlerOperations.java

public Object div(Object o1, Object o2) {
    if (BigDecimal.class.isInstance(o1) && Number.class.isInstance(o2)) {
        return ((BigDecimal) o1).divide(asBigDecimal((Number) o2), MathContext.DECIMAL128);
    }//from  ww  w  . j a v a2  s  .co  m
    if (Number.class.isInstance(o1) && BigDecimal.class.isInstance(o2)) {
        return asBigDecimal((Number) o1).divide((BigDecimal) o2, MathContext.DECIMAL128);
    }
    if (Double.class.isInstance(o1) && Number.class.isInstance(o2)) {
        return new Double(((Double) o1).doubleValue() / ((Number) o2).doubleValue());
    }
    if (Long.class.isInstance(o1) && Number.class.isInstance(o2)) {
        return new Long((long) (((Long) o1).doubleValue() / ((Number) o2).doubleValue()));
    }
    log.error("Cannot make division for " + o1.getClass() + " with " + o2.getClass());
    return null;
}