Example usage for java.math BigDecimal doubleValue

List of usage examples for java.math BigDecimal doubleValue

Introduction

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

Prototype

@Override
public double doubleValue() 

Source Link

Document

Converts this BigDecimal to a double .

Usage

From source file:fsm.series.Series_CF.java

public double getF4Value(double y, int m, int n) {
    double Pi = Math.PI;

    double um = getMu_m(m);
    double un = getMu_m(n);
    double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um));

    double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un));
    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd2;/*w  w  w  . j a va2 s  .  c  o  m*/
    BigDecimal Ynd2;

    BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(-km * km * sin(km * y));
    BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y));

    Ymd2 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(alphaN * kn * kn * cosh(kn * y));

    BigDecimal sinhN = new BigDecimal(-kn * kn * sinh(kn * y));
    BigDecimal sinN = new BigDecimal(-kn * kn * sin(kn * y));
    BigDecimal cosN = new BigDecimal(alphaN * kn * kn * cos(kn * y));

    Ynd2 = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd2.multiply(Ynd2);

    return ans.doubleValue();
}

From source file:fsm.series.Series_CF.java

public double getF5Value(double y, int m, int n) {

    double um = getMu_m(m);
    double un = getMu_m(n);
    double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um));

    double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un));
    double km = um / a;
    double kn = un / a;

    BigDecimal Ymd1;//from  w w w.  j  a va  2s  . c  o m
    BigDecimal Ynd1;

    BigDecimal cosh = new BigDecimal(-km * cosh(km * y));

    BigDecimal sinh = new BigDecimal(alphaM * km * sinh(km * y));
    BigDecimal sin = new BigDecimal(alphaM * km * sin(km * y));
    BigDecimal cos = new BigDecimal(km * cos(km * y));

    Ymd1 = (cos.add(sin).add(sinh).add(cosh));

    BigDecimal coshN = new BigDecimal(-kn * cosh(kn * y));

    BigDecimal sinhN = new BigDecimal(alphaN * kn * sinh(kn * y));
    BigDecimal sinN = new BigDecimal(alphaN * kn * sin(kn * y));
    BigDecimal cosN = new BigDecimal(kn * cos(kn * y));

    Ynd1 = cosN.add(sinN).add(sinhN).add(coshN);

    BigDecimal ans = Ymd1.multiply(Ynd1);

    return ans.doubleValue();

}

From source file:org.projectforge.statistics.TimesheetDisciplineChartBuilder.java

/**
 * Ein Diagramm, welches ber die letzten n Tage die kummulierten IST-Arbeitsstunden und als Soll-Wert die tatschlich gebuchten
 * Zeitberichte auftrgt. Dies wird in einem Differenz-XY-Diagramm visualisiert. Die Darstellung soll motivieren, dass Projektmitarbeiter
 * ihre Zeitberichte mglichst zeitnah eintragen.
 * @param timesheetDao/*from   w  ww  .  j  a  va2s  .co  m*/
 * @param userId
 * @param workingHoursPerDay
 * @param forLastNDays
 * @param shape e. g. new Ellipse2D.Float(-3, -3, 6, 6) or null, if no marker should be printed.
 * @param stroke e. g. new BasicStroke(3.0f).
 * @param showAxisValues
 * @return
 */
public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final double workingHoursPerDay,
        final short forLastNDays, final Shape shape, final Stroke stroke, final boolean showAxisValues) {
    final DayHolder dh = new DayHolder();
    final TimesheetFilter filter = new TimesheetFilter();
    filter.setStopTime(dh.getDate());
    dh.add(Calendar.DATE, -forLastNDays);
    filter.setStartTime(dh.getDate());
    filter.setUserId(userId);
    filter.setOrderType(OrderDirection.ASC);
    final List<TimesheetDO> list = timesheetDao.getList(filter);
    final TimeSeries sollSeries = new TimeSeries("Soll");
    final TimeSeries istSeries = new TimeSeries("Ist");
    planWorkingHours = 0;
    actualWorkingHours = 0;
    final Iterator<TimesheetDO> it = list.iterator();
    TimesheetDO current = null;
    if (it.hasNext() == true) {
        current = it.next();
    }
    for (int i = 0; i <= forLastNDays; i++) {
        while (current != null && (dh.isSameDay(current.getStartTime()) == true
                || current.getStartTime().before(dh.getDate()) == true)) {
            actualWorkingHours += ((double) current.getWorkFractionDuration()) / 3600000;
            if (it.hasNext() == true) {
                current = it.next();
            } else {
                current = null;
                break;
            }
        }
        if (dh.isWorkingDay() == true) {
            final BigDecimal workFraction = dh.getWorkFraction();
            if (workFraction != null) {
                planWorkingHours += workFraction.doubleValue() * workingHoursPerDay;
            } else {
                planWorkingHours += workingHoursPerDay;
            }
        }
        final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear());
        sollSeries.add(day, planWorkingHours);
        istSeries.add(day, actualWorkingHours);
        dh.add(Calendar.DATE, 1);
    }
    return create(sollSeries, istSeries, shape, stroke, showAxisValues, "hours");
}

From source file:com.streamsets.pipeline.stage.origin.jdbc.CommonSourceConfigBean.java

public RateLimiter creatQueryRateLimiter() {
    final BigDecimal rateLimit = new BigDecimal(queriesPerSecond);
    if (rateLimit.signum() < 1) {
        // negative or zero value; no rate limit
        return null;
    } else {/*from  w ww . j av  a  2s .co  m*/
        return RateLimiter.create(rateLimit.doubleValue());
    }
}

From source file:it.govpay.core.utils.RtUtils.java

private static void validaSemantica(CtDatiVersamentoRPT rpt, CtDatiVersamentoRT rt, EsitoValidazione esito) {

    valida(rpt.getCodiceContestoPagamento(), rt.getCodiceContestoPagamento(), esito,
            "CodiceContestoPagamento non corrisponde", true);
    valida(rpt.getIdentificativoUnivocoVersamento(), rt.getIdentificativoUnivocoVersamento(), esito,
            "IdentificativoUnivocoVersamento non corrisponde", true);

    Rpt.EsitoPagamento esitoPagamento = validaSemanticaCodiceEsitoPagamento(rt.getCodiceEsitoPagamento(),
            esito);//from  w w  w .  j  ava 2  s .c  o m

    // Se siamo in pagamento eseguito, parzialmente eseguito o parzialmente decorso, devono esserci tanti versamenti quanti pagamenti.
    if (esitoPagamento != null) {
        switch (esitoPagamento) {
        case DECORRENZA_TERMINI_PARZIALE:
        case PAGAMENTO_ESEGUITO:
        case PAGAMENTO_PARZIALMENTE_ESEGUITO:
            if (rt.getDatiSingoloPagamento().size() != rpt.getDatiSingoloVersamento().size()) {
                esito.addErrore("Numero di pagamenti diverso dal numero di versamenti per una ricevuta di tipo "
                        + esitoPagamento.name(), true);
                return;
            }
        case DECORRENZA_TERMINI:
        case PAGAMENTO_NON_ESEGUITO:
            if (rt.getDatiSingoloPagamento().size() != 0
                    && rt.getDatiSingoloPagamento().size() != rpt.getDatiSingoloVersamento().size()) {
                esito.addErrore("Numero di pagamenti diverso dal numero di versamenti per una ricevuta di tipo "
                        + esitoPagamento.name(), true);
                return;
            }
        }
    }

    BigDecimal importoTotaleCalcolato = BigDecimal.ZERO;

    for (int i = 0; i < rpt.getDatiSingoloVersamento().size(); i++) {

        CtDatiSingoloVersamentoRPT singoloVersamento = rpt.getDatiSingoloVersamento().get(i);
        CtDatiSingoloPagamentoRT singoloPagamento = null;
        if (rt.getDatiSingoloPagamento().size() != 0) {
            singoloPagamento = rt.getDatiSingoloPagamento().get(i);
            validaSemanticaSingoloVersamento(singoloVersamento, singoloPagamento, esito);
            importoTotaleCalcolato = importoTotaleCalcolato.add(singoloPagamento.getSingoloImportoPagato());
        }
    }

    if (importoTotaleCalcolato.compareTo(rt.getImportoTotalePagato()) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] non corrisponde alla somma dei SingoliImportiPagati ["
                + importoTotaleCalcolato.doubleValue() + "]", true);
    if (esitoPagamento == Rpt.EsitoPagamento.PAGAMENTO_NON_ESEGUITO
            && rt.getImportoTotalePagato().compareTo(BigDecimal.ZERO) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da 0 per un pagamento con esito 'Non Eseguito'.", true);
    if (esitoPagamento == Rpt.EsitoPagamento.DECORRENZA_TERMINI
            && rt.getImportoTotalePagato().compareTo(BigDecimal.ZERO) != 0)
        esito.addErrore("ImportoTotalePagato [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da 0 per un pagamento con esito 'Decorrenza temini'.", true);
    if (esitoPagamento == Rpt.EsitoPagamento.PAGAMENTO_ESEGUITO
            && rt.getImportoTotalePagato().compareTo(rpt.getImportoTotaleDaVersare()) != 0)
        esito.addErrore("Importo totale del pagamento [" + rt.getImportoTotalePagato().doubleValue()
                + "] diverso da quanto richiesto [" + rpt.getImportoTotaleDaVersare().doubleValue() + "]",
                false);
}

From source file:com.mobileman.projecth.business.patient.PatientKeyPerformanceIndicatorServiceTest.java

/**
 * /*from www. java  2s.c  om*/
 * @throws Exception
 */
@Test
public void computeKPI_CDAI() throws Exception {
    Patient patient = (Patient) userService.findUserByLogin("sysuser1");
    assertNotNull(patient);

    Disease rheuma = diseaseService.findByCode("M79.0");
    assertNotNull(rheuma);

    KeyPerformanceIndicatorType kpi = keyPerformanceIndicatorTypeService
            .find(KeyPerformanceIndicatorType.Type.CDAI, rheuma.getId());

    BigDecimal result = patientKPIService.computeKPI(patient.getId(), kpi.getId(), dateFormat.parse("1.2.2010"),
            dateFormat.parse("1.12.2010"));
    assertEquals(10.33d, result.doubleValue(), 0.01);

    result = patientKPIService.computeKPI(patient.getId(), kpi.getId(), dateFormat.parse("3.11.2010"),
            dateFormat.parse("3.11.2010"));
    assertEquals(13.00d, result.doubleValue(), 0.01);
}

From source file:com.mobileman.projecth.business.patient.PatientKeyPerformanceIndicatorServiceTest.java

/**
 * //from   w ww.  java 2s.  c o m
 * @throws Exception
 */
@Test
public void computeKpi_BASDAI() throws Exception {
    Patient patient = (Patient) userService.findUserByLogin("sysuser1");
    assertNotNull(patient);

    Disease morbusBechterew = diseaseService.findByCode("M45");
    assertNotNull(morbusBechterew);

    KeyPerformanceIndicatorType kpi = keyPerformanceIndicatorTypeService
            .find(KeyPerformanceIndicatorType.Type.BASDAI, morbusBechterew.getId());

    BigDecimal result = patientKPIService.computeKPI(patient.getId(), kpi.getId(),
            dateFormat.parse("1.11.2010"), dateFormat.parse("2.11.2010"));
    assertEquals(5.8d, result.doubleValue(), 0.001);

    result = patientKPIService.computeKPI(patient.getId(), kpi.getId(), dateFormat.parse("2.11.2010"),
            dateFormat.parse("2.11.2010"));
    assertEquals(5.5d, result.doubleValue(), 0.001);

    result = patientKPIService.computeKPI(patient.getId(), kpi.getId(), dateFormat.parse("3.11.2010"),
            dateFormat.parse("3.11.2010"));
    assertEquals(0.0d, result.doubleValue(), 0.001);
}

From source file:fixio.fixprotocol.fields.FieldFactoryTest.java

@Test
public void testValueOfQty() throws Exception {
    BigDecimal value = BigDecimal.valueOf(new Random().nextInt()).movePointLeft(5);

    FloatField field = FieldFactory.valueOf(FieldType.OrderQty.tag(), value.toPlainString().getBytes(US_ASCII));

    assertEquals("tagnum", FieldType.OrderQty.tag(), field.getTagNum());
    assertEquals("value", value.doubleValue(), field.getValue().doubleValue(), 0.0);
    assertEquals("value", value.floatValue(), field.floatValue(), 0.0);
}

From source file:fixio.fixprotocol.fields.FieldFactoryTest.java

@Test
public void testValueOfPrice() throws Exception {
    BigDecimal value = BigDecimal.valueOf(new Random().nextInt()).movePointLeft(5);

    FloatField field = FieldFactory.valueOf(FieldType.MktBidPx.tag(), value.toPlainString().getBytes(US_ASCII));

    assertEquals("tagnum", FieldType.MktBidPx.tag(), field.getTagNum());
    assertEquals("value", value.doubleValue(), field.getValue().doubleValue(), 0.0);
    assertEquals("value", value.floatValue(), field.floatValue(), 0.0);
}

From source file:ch.algotrader.service.algo.TickwiseIncrementalOrderService.java

@Override
protected IncrementalOrderStateVO handleValidateOrder(final TickwiseIncrementalOrder algoOrder) {
    Security security = algoOrder.getSecurity();
    SecurityFamily family = security.getSecurityFamily();

    TickVO tick = (TickVO) this.marketDataCacheService.getCurrentMarketDataEvent(security.getId());

    // check spread and adjust offsetTicks if spread is too narrow
    int spreadTicks = family.getSpreadTicks(null, tick.getBid(), tick.getAsk());
    int adjustedStartOffsetTicks = algoOrder.getStartOffsetTicks();
    int adjustedEndOffsetTicks = algoOrder.getEndOffsetTicks();

    // adjust offsetTicks if needed
    if (spreadTicks < (algoOrder.getStartOffsetTicks() - algoOrder.getEndOffsetTicks())) {

        // first reduce startOffsetTicks to min 0
        adjustedStartOffsetTicks = Math.max(spreadTicks + algoOrder.getEndOffsetTicks(), 0);
        if (spreadTicks < (adjustedStartOffsetTicks - algoOrder.getEndOffsetTicks())) {

            // if necessary also increase endOffstTicks to max 0
            adjustedEndOffsetTicks = Math.min(adjustedStartOffsetTicks - spreadTicks, 0);
        }//  www .  j  a v a  2s . c o  m
    }

    BigDecimal startLimit;
    BigDecimal endLimit;
    if (Side.BUY.equals(algoOrder.getSide())) {
        startLimit = family.adjustPrice(null, tick.getBid(), adjustedStartOffsetTicks);
        endLimit = family.adjustPrice(null, tick.getAsk(), adjustedEndOffsetTicks);

        if (startLimit.doubleValue() <= 0.0) {
            startLimit = family.adjustPrice(null, new BigDecimal(0), 1);
        }

    } else {

        startLimit = family.adjustPrice(null, tick.getAsk(), -adjustedStartOffsetTicks);
        endLimit = family.adjustPrice(null, tick.getBid(), -adjustedEndOffsetTicks);

        if (startLimit.doubleValue() <= 0.0) {
            startLimit = family.adjustPrice(null, new BigDecimal(0), 1);
        }

        if (endLimit.doubleValue() <= 0.0) {
            endLimit = family.adjustPrice(null, new BigDecimal(0), 1);
        }
    }

    return new IncrementalOrderStateVO(startLimit, endLimit, startLimit);
}