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:cherry.foundation.type.jdbc.JdbcSecureBigDecimalTest.java

@Test
public void testSaveAndLoad() {
    BigDecimal plain = BigDecimal.valueOf(random.nextDouble());
    ConversionTest record = new ConversionTest();
    record.setSecBigdec(SecureBigDecimal.plainValueOf(plain));

    KeyHolder keyHolder = new GeneratedKeyHolder();
    int count = jdbcDao.insert(record, keyHolder);

    assertThat(count, is(1));/*w ww .  j a v  a 2  s  . com*/
    assertThat(keyHolder.getKey().intValue(), is(not(0)));

    List<ConversionTest> list = jdbcDao.selectAll();
    assertThat(list.isEmpty(), is(false));
    ConversionTest r = list.get(0);
    assertThat(r.getSecBigdec().plain(), is(plain));
}

From source file:fr.landel.utils.commons.NumberUtils.java

/**
 * Get the max decimal length.//from   w  ww  . j  a  v a  2s. com
 * 
 * @param num1
 *            double
 * @param num2
 *            double
 * @return the max decimal length
 */
private static Integer getMaxDecimalsLength(final Double num1, final Double num2) {
    return Math.max(BigDecimal.valueOf(num1).scale(), BigDecimal.valueOf(num2).scale());
}

From source file:fuzzy.util.MaxMF.java

public Map<Double, Double> evaluate(Collection<T> x, MembershipFunction<T> mf) {
    Map<Double, Double> max = new HashMap<Double, Double>();
    BigDecimal maxValue = BigDecimal.valueOf(0.0);
    boolean first = true;
    for (T value : x) {
        BigDecimal temp = new BigDecimal(mf.evaluate(value), new MathContext(precision, roundingMode));
        if (first || temp.compareTo(maxValue) > 0) {
            first = false;//from  ww  w  .ja va 2 s  .c  om
            maxValue = temp;
            max.clear();
            max.put(value.doubleValue(), temp.doubleValue());
        } else if (temp.compareTo(maxValue) == 0) {
            max.put(value.doubleValue(), temp.doubleValue());
        } // else ignore since it's less than the maximum value
    }
    return max;
}

From source file:com.miko.demo.mongo.service.EntityCCreationTest.java

@Test
public void createEntityCWithAttributes() {
    EntityC entityC = new EntityC("mirage", BigDecimal.valueOf(2));
    entityC.setAttribute("mirage1", "value1");
    entityC.setAttribute("mirage2", "value2");

    entityC = entityCService.save(entityC);

    Assert.notNull(entityC.getId());//www  .ja  v a  2s.c  o  m
}

From source file:co.com.soinsoftware.altablero.controller.NoteValueController.java

private NoteValueBO buildNoteValueFromString(final String objectStr) {
    NoteValueBO noteValue = null;/*from  w w  w .j  a v a  2  s .c o  m*/
    final String[] properties = objectStr.split(";");
    int idNoteDefinition = 0;
    int idStudent = 0;
    BigDecimal value = null;
    for (int i = 0; i < properties.length; i++) {
        final String[] property = properties[i].split("=");
        switch (property[0]) {
        case "idNoteDefinition":
            idNoteDefinition = Integer.valueOf(property[1]);
            break;
        case "idStudent":
            idStudent = Integer.valueOf(property[1]);
            break;
        case "value":
            value = BigDecimal.valueOf(Double.valueOf(property[1].replace("_", "")));
            break;
        }
        if (idNoteDefinition > 0 && idStudent > 0 && value != null) {
            noteValue = new NoteValueBO(idNoteDefinition, idStudent, value);
        }
    }
    return noteValue;
}

From source file:com.miko.demo.postgresql.service.EntityCCreationTest.java

@Test
public void createEntityCWithAttributes() {
    EntityC entityC = new EntityC("mirage", BigDecimal.valueOf(2));
    entityC.setAttribute("mirage1", "value1");
    entityC.setAttribute("mirage2", "value2");

    entityC = entityCService.save(entityC);

    Assert.notNull(entityC.getOid());//ww w .j a  va2  s  . c  om
}

From source file:lu.lippmann.cdb.graph.renderer.CadralEdgeColorTransformer.java

/**
 * //  www .j  a v  a  2s.c  o  m
 * @param color1
 * @param color2
 * @param nb
 * @return
 */
private List<Color> getColorList() {

    final List<Color> res = new ArrayList<Color>();

    for (int i = 0; i < nbColors; i++) {
        res.add(rangeColor(color1, color2, BigDecimal.valueOf(i), BigDecimal.ZERO,
                BigDecimal.valueOf(nbColors)));
    }
    return res;
}

From source file:org.fineract.module.stellar.controller.JournalEntryPaymentMapper.java

PaymentPersistency mapToPayment(final String mifosTenantId, final JournalEntryData journalEntryData)
        throws InvalidJournalEntryException {

    Preconditions.checkNotNull(journalEntryData);
    if ((journalEntryData.transactionDetails == null) || (journalEntryData.currency == null)
            || (journalEntryData.amount == null) || (journalEntryData.transactionDetails.paymentDetails == null)
            || (journalEntryData.transactionDetails.paymentDetails.routingCode == null)
            || (journalEntryData.transactionDetails.paymentDetails.accountNumber == null)
            || (journalEntryData.transactionDetails.paymentDetails.bankNumber == null)
            || (journalEntryData.currency.inMultiplesOf == null) || (journalEntryData.currency.code == null)) {
        throw new InvalidJournalEntryException();
    }/*from w  w w . j a  v  a2s  . c  o m*/

    final PaymentPersistency ret = new PaymentPersistency();

    ret.assetCode = journalEntryData.currency.code;
    ret.amount = journalEntryData.amount.multiply(BigDecimal.valueOf(journalEntryData.currency.inMultiplesOf));
    ret.sourceTenantId = mifosTenantId;
    ret.targetAccount = journalEntryData.transactionDetails.paymentDetails.accountNumber;
    ret.sinkDomain = journalEntryData.transactionDetails.paymentDetails.bankNumber;
    ret.isStellarPayment = (journalEntryData.transactionDetails.paymentDetails.routingCode
            .equals(STELLAR_ROUTING_CODE));
    ret.targetSubAccount = "";

    return ret;
}

From source file:edu.zipcloud.cloudstreetmarket.core.converters.YahooQuoteToIndexConverter.java

@Override
public Index convert(YahooQuote yahooQuote) {

    Index index = indexRepository.findOne(yahooQuote.getId());
    if (index == null) {
        index = new Index();
        index.setId(yahooQuote.getId());
    }//  w  w  w. j  a v  a2  s .  c  om

    index.setName(yahooQuote.getName());
    index.setOpen(BigDecimal.valueOf(yahooQuote.getOpen()));
    index.setHigh(BigDecimal.valueOf(yahooQuote.getHigh()));
    index.setLow(BigDecimal.valueOf(yahooQuote.getLow()));
    index.setDailyLatestChange(BigDecimal.valueOf(yahooQuote.getLastChange()));
    index.setDailyLatestChangePercent(BigDecimal.valueOf(yahooQuote.getLastChangePercent()));
    index.setDailyLatestValue(BigDecimal.valueOf(yahooQuote.getLast()));
    index.setPreviousClose(BigDecimal.valueOf(yahooQuote.getPreviousClose()));
    index.setComponents(Sets.newHashSet());
    if (!StringUtils.isEmpty(yahooQuote.getExchange())) {
        index.setExchange(exchangeService.get(yahooQuote.getExchange()));
    }
    return index;
}

From source file:com.platform.camel.multicasting_messages.MulticastingRouteSpringTest.java

@Before
public void setUp() throws Exception {
    super.setUp();

    mockA.whenAnyExchangeReceived(new Processor() {
        public void process(Exchange exchange) throws Exception {
            Thread.sleep(950);/*from  w  w  w. j a v  a 2 s .co  m*/
            exchange.getIn().setBody(BigDecimal.valueOf(3));
        }
    });
    mockB.whenAnyExchangeReceived(new Processor() {
        public void process(Exchange exchange) throws Exception {
            Thread.sleep(900);
            exchange.getIn().setBody(BigDecimal.valueOf(5));
        }
    });
    mockC.whenAnyExchangeReceived(new Processor() {
        public void process(Exchange exchange) throws Exception {
            Thread.sleep(850);
            exchange.getIn().setBody(BigDecimal.valueOf(1));
        }
    });
}