Example usage for java.math BigDecimal valueOf

List of usage examples for java.math BigDecimal valueOf

Introduction

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

Prototype

public static BigDecimal valueOf(double val) 

Source Link

Document

Translates a double into a BigDecimal , using the double 's canonical string representation provided by the Double#toString(double) method.

Usage

From source file:org.impotch.calcul.assurancessociales.CalculCotisationAvsAiApgIndependantTest.java

private static BigDecimal getTxTotal(CalculCotisationAvsAiApgIndependant calculateur, int revenuDeterminant) {
    return calculateur.getTauxTotal(BigDecimal.valueOf(revenuDeterminant));
}

From source file:com.wavemaker.json.JSONMarshallerTest.java

public void testNumericTypes() throws Exception {

    JSONState jc = new JSONState();

    ObjectWithTypes owt = new ObjectWithTypes();
    owt.setBigDecimal(BigDecimal.valueOf(12.2));
    owt.setIntVal(12);// w  w  w.jav  a 2s.c o  m
    owt.setFloatVal(13.3f);
    owt.setBigInteger(BigInteger.valueOf(13));
    owt.setBoolVal(false);

    String s = JSONMarshaller.marshal(owt, jc, false);
    assertEquals("{\"bigDecimal\":12.2,\"bigInteger\":13,\"boolVal\":false,\"floatVal\":13.3,\"intVal\":12}",
            s);

    assertEquals(s, StringUtils.deleteWhitespace(JSONUnmarshaller.unmarshal(s).toString()));
}

From source file:org.killbill.billing.plugin.avatax.dao.AvaTaxDao.java

public void addResponse(final UUID kbAccountId, final UUID kbInvoiceId,
        final Map<UUID, Iterable<InvoiceItem>> kbInvoiceItems, final TaxRateResult taxRateResult,
        final DateTime utcNow, final UUID kbTenantId) throws SQLException {
    execute(dataSource.getConnection(), new WithConnectionCallback<Void>() {
        @Override/*w w  w .java2s .  co  m*/
        public Void withConnection(final Connection conn) throws SQLException {
            DSL.using(conn, dialect, settings)
                    .insertInto(AVATAX_RESPONSES, AVATAX_RESPONSES.KB_ACCOUNT_ID,
                            AVATAX_RESPONSES.KB_INVOICE_ID, AVATAX_RESPONSES.KB_INVOICE_ITEM_IDS,
                            AVATAX_RESPONSES.TOTAL_TAX, AVATAX_RESPONSES.RESULT_CODE,
                            AVATAX_RESPONSES.CREATED_DATE, AVATAX_RESPONSES.KB_TENANT_ID)
                    .values(kbAccountId.toString(), kbInvoiceId.toString(),
                            kbInvoiceItemsIdsAsString(kbInvoiceItems),
                            BigDecimal.valueOf(taxRateResult.totalRate), SUCCESS, toTimestamp(utcNow),
                            kbTenantId.toString())
                    .execute();
            return null;
        }
    });
}

From source file:de.metas.procurement.webui.util.DummyDataProducer.java

private SyncBPartnersRequest createSyncBPartnersRequest() {
    final SyncBPartnersRequest request = new SyncBPartnersRequest();

    ////from  ww  w . ja  v a 2  s . c o m
    // BPartner
    {
        final SyncBPartner syncBPartner = new SyncBPartner();
        syncBPartner.setUuid(randomUUID());
        syncBPartner.setName("test-bp01");
        syncBPartner.setUsers(Arrays.asList(createSyncUser("test", "q", null),
                createSyncUser("teo.sarca@gmail.com", "q", null), createSyncUser("test_en", "q", "en_US"),
                createSyncUser("test_de", "q", "de_DE")));

        //
        // Contract
        {
            syncBPartner.setSyncContracts(true);

            final SyncContract syncContract = new SyncContract();
            syncContract.setUuid(randomUUID());
            syncContract.setDateFrom(contractDateFrom);
            syncContract.setDateTo(contractDateTo);

            final SyncProductsRequest syncProductsRequest = getSyncProductsRequest();
            for (final SyncProduct syncProduct : syncProductsRequest.getProducts().subList(0, 6)) {
                final SyncContractLine syncContractLine = new SyncContractLine();
                syncContractLine.setUuid(randomUUID());
                syncContractLine.setProduct(syncProduct);

                syncContract.getContractLines().add(syncContractLine);
            }

            syncBPartner.getContracts().add(syncContract);
        }

        //
        // RfQ
        final List<SyncProduct> syncProducts = getSyncProductsRequest().getProducts();
        for (int rfqNo = 0; rfqNo < 4 && rfqNo < syncProducts.size(); rfqNo++) {
            final Date dateStart = DateUtils.addMonths(DateUtils.truncToMonth(new Date()), 2);
            final Date dateEnd = DateUtils.addDays(dateStart, 14);
            final Date dateClose = DateUtils.addDays(dateStart, -10);

            final SyncRfQ syncRfQ = new SyncRfQ();
            syncRfQ.setUuid(randomUUID());

            syncRfQ.setDateStart(dateStart);
            syncRfQ.setDateEnd(dateEnd);

            syncRfQ.setBpartner_uuid(syncBPartner.getUuid());

            syncRfQ.setDateClose(dateClose);

            final SyncProduct syncProduct = syncProducts.get(rfqNo);
            syncRfQ.setProduct(syncProduct);

            syncRfQ.setQtyRequested(BigDecimal.valueOf(100));
            syncRfQ.setQtyCUInfo("Kg");
            syncRfQ.setCurrencyCode("CHF");

            syncBPartner.getRfqs().add(syncRfQ);
        }

        request.getBpartners().add(syncBPartner);
    }

    return request;
}

From source file:com.chiralbehaviors.seurat.service.DemoScenarioTest.java

private void addItem(PricedProduct product, Order order, int quantity, double discount, double taxRate,
        Model model) throws InstantiationException {
    ItemDetail item = model.construct(ItemDetail.class, "an item", "a real item");
    item.setProduct(product);/*from   ww w . j ava2  s.co m*/
    item.setUnitPrice(product.getUnitPrice());
    item.setDiscount(BigDecimal.valueOf(discount));
    item.setQuantity(quantity);
    item.setTaxRate(BigDecimal.valueOf(taxRate));
    order.addItemDetail(item);
}

From source file:org.gofleet.openLS.ddbb.dao.postgis.PostGisHBRoutingDAO.java

private RouteSummaryType getRouteSummary(Double cost) {
    RouteSummaryType res = new RouteSummaryType();
    DistanceType coste = new DistanceType();
    if (cost.isInfinite() || cost.isNaN())
        coste.setValue(BigDecimal.valueOf(0d));
    else//from   ww w . ja  v a 2s . c o m
        coste.setValue(BigDecimal.valueOf(cost));
    res.setTotalDistance(coste);
    return res;
}

From source file:net.sourceforge.fenixedu.domain.student.importation.DegreeCandidateDTO.java

/**
 * <pre>/*from  w w w. j  a v  a  2s  .  c  o  m*/
 * 
 * EstabCol(0)   CursoCol (cods old)(1)   NumBI(2)   LocBI(3)   Descr loc BI(4)   Check Digit(5)   Nome(6)   Morada1(7)   
 * Morada2(8)   Codpos(9)   Codpos3(10)   CodLocal(11)   Telefone(12)   Sexo(13)   DataNasc(dd-MMM-yy)(14)   
 * Conting(15)   PrefCol (op ingresso)(16)   EtapCol(17)   Media12(18)   NotaCand(19)   cod_escola_sec(20)   
 * escola_sec(21)   tipo_estab_sec(22)   curso_secundario(23)
 * 
 * </pre>
 */

@Override
public boolean fillWithFileLineData(String dataLine) {

    if (StringUtils.isEmpty(dataLine.trim()) || dataLine.startsWith("#")) {
        return false;
    }

    final String[] fields = dataLine.split("\t");
    this.degreeCode = fields[1].trim();
    this.documentIdNumber = fields[2].trim();
    this.documentCheckDigit = fields[5].trim();
    this.name = fields[6].trim();
    this.address = fields[7].trim() + " " + fields[8].trim();
    this.areaCode = fields[9].trim() + "-" + fields[10].trim();
    this.areaOfAreaCode = fields[11].trim();
    this.phoneNumber = fields[12].trim();
    this.gender = String2Gender.convert(fields[13].trim());
    this.dateOfBirth = parseDate(fields[14].trim());
    this.contigent = fields[15].trim();
    this.ingression = DgesBaseProcess.CONTINGENT_TO_INGRESSION_CONVERSION.get(this.contigent);
    this.placingOption = Integer.valueOf(fields[16].trim());
    this.highSchoolFinalGrade = new BigDecimal(fields[18].trim()).divide(BigDecimal.valueOf(10))
            .toPlainString();
    this.entryGrade = new BigDecimal(fields[19].trim().replace(',', '.')).doubleValue();
    this.highSchoolName = fields[21].trim();
    this.highSchoolType = parseHighSchoolType(fields[22].trim());
    this.highSchoolDegreeDesignation = fields[23].trim();

    return true;
}

From source file:org.jtotus.database.NetworkGoogle.java

public BigDecimal fetchDataInternal(String stockName, DateTime endDate, int type) {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet httpGet = null;/*  w ww .ja  v a  2s . co  m*/
    DateTime startDate = endDate.minusDays(5);
    BigDecimal retValue = null;
    try {
        DateTimeFormatter formatterOUT = DateTimeFormat.forPattern(timePatternForWrite);
        DateTimeFormatter formatterIN = DateTimeFormat.forPattern(timePatternForRead);

        String query = url + "?q=" + names.getHexName(stockName) + "&" + "startdate="
                + formatterOUT.print(startDate) + "&" + "enddate=" + formatterOUT.print(endDate) + "&"
                + "&num=30&output=csv";

        System.out.printf("HttpGet:%s : date:%s\n", query, formatterOUT.print(startDate));
        httpGet = new HttpGet(query);

        HttpResponse response = client.execute(httpGet);
        StatusLine status = response.getStatusLine();
        if (status.getStatusCode() != 200) {
            throw new IOException("Invalid response from server: " + status.toString());
        }

        HttpEntity entity = response.getEntity();

        BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));

        //            Date, Open,High,Low,Close,Volume
        String line = reader.readLine(); //Header
        while ((line = reader.readLine()) != null) {
            String[] values = line.split(",");
            double value = Double.parseDouble(values[type]);
            retValue = BigDecimal.valueOf(value);
        }

    } catch (IOException ex) {
        System.err.printf("Unable to find market data for: %s - %s\n", names.getHexName(stockName), stockName);
    } catch (IllegalArgumentException ex) {
        System.err.printf("Unable to find market data for: %s - %s\n", names.getHexName(stockName), stockName);
    } finally {
        if (httpGet != null) {
            //FIXME: what to do ?
        }
    }

    return retValue;
}

From source file:de.hybris.platform.b2bacceleratorfacades.order.impl.DefaultCartFacade.java

private PriceData createPrice(final PriceData currentEntryPrice, final PriceData orderEntryPrice) {
    return getPriceDataFactory().create(currentEntryPrice.getPriceType(),
            BigDecimal
                    .valueOf(orderEntryPrice.getValue().longValue() + currentEntryPrice.getValue().longValue()),
            currentEntryPrice.getCurrencyIso());
}

From source file:ec.com.espe.arqui.web.AsignarRecursosBean.java

public void agregarProductoDetalle() {
    if (this.productoSelected != null) {
        if (this.listaDetalleFactura == null)
            this.listaDetalleFactura = new ArrayList<>();

        DetalleFactura df = new DetalleFactura();
        df.setCodigoProducto(this.productoSelected.getCodigo());
        df.setProducto(this.productoSelected);
        df.setCantidad(this.cantidad);
        df.setCostoUnitario(this.productoSelected.getPrecioUnitario());
        BigDecimal total = this.productoSelected.getPrecioUnitario()
                .multiply(BigDecimal.valueOf((double) cantidad));
        df.setCostoTotal(total);/*  w w  w  . j ava 2s .  co  m*/

        this.listaDetalleFactura.add(df);
    }
}