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.apache.camel.howto.MulticastingRouteSpringTest.java

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

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

From source file:org.wicketstuff.gmap.api.GLatLng.java

@Override
public String getJSconstructor() {

    return new Constructor("google.maps.LatLng").add(BigDecimal.valueOf(lat).toString())
            .add(BigDecimal.valueOf(lng).toString()).add(Boolean.valueOf(unbounded)).toJS();
}

From source file:org.openmhealth.schema.domain.omh.UnitValue.java

public UnitValue(String unit, double value) {
    this(unit, BigDecimal.valueOf(value));
}

From source file:com.trenako.repositories.mongo.CollectionsRepositoryTests.java

private Money USD100() {
    return new Money(BigDecimal.valueOf(100), "USD");
}

From source file:org.camelcookbook.transformation.csv.CsvSpringTest.java

@Test
public void testCsvMarshal() throws Exception {
    ArrayList<BookModel> books = new ArrayList<BookModel>();

    final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM-yyyy");

    BookModel book = new BookModel();
    book.setCategory("PROGRAMMING");
    book.setTitle("Camel in Action");
    book.setTitleLanguage("en");
    book.setAuthor1("Claus Ibsen");
    book.setAuthor2("Jon Anstey");
    book.setPublishDate(simpleDateFormat.parse("Dec-2010"));
    book.setPrice(BigDecimal.valueOf(49.99));

    books.add(book);/* w w w. j  a  va  2s.  co  m*/

    book = new BookModel();
    book.setCategory("PROGRAMMING");
    book.setTitle("Apache Camel Developer's Cookbook");
    book.setTitleLanguage("en");
    book.setAuthor1("Scott Cranton");
    book.setAuthor2("Jakub Korab");
    book.setPublishDate(simpleDateFormat.parse("Dec-2013"));
    book.setPrice(BigDecimal.valueOf(49.99));

    books.add(book);

    final String response = template.requestBody("direct:marshal", books, String.class);

    log.info(response);
    final String expects = "PROGRAMMING,Camel in Action,en,Claus Ibsen,Jon Anstey,Dec-2010,49.99\n"
            + "PROGRAMMING,Apache Camel Developer's Cookbook,en,Scott Cranton,Jakub Korab,Dec-2013,49.99\n";
    assertEquals(expects, response);
}

From source file:com.trenako.web.controllers.form.CollectionItemFormTests.java

@Test
public void shouldReturnCollectionItemsToBeAdded() {
    CollectionItemForm form = CollectionItemForm.newForm(rollingStock(), messageSource);

    form.setPrice(BigDecimal.valueOf(100));
    CollectionItem item = form.getItem();
    item.setNotes("My notes");
    item.setCondition("new");
    item.setAddedAt(date("2012/09/01"));

    CollectionItem newItem = form.newItem(rollingStock(), georgeStephenson());

    assertEquals("My notes", newItem.getNotes());
    assertEquals("new", newItem.getCondition());
    assertEquals(date("2012/09/01"), newItem.getAddedAt());
    assertEquals("2012-09-01_acme-123456", newItem.getItemId());
    assertEquals("$100.00", newItem.getPrice().toString());
}

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

@Override
public StockProduct convert(YahooQuote yahooQuote) {
    StockProduct stockProduct = stockProductRepository.findOne(yahooQuote.getId());
    if (stockProduct == null) {
        stockProduct = new StockProduct();
        stockProduct.setId(yahooQuote.getId());
    }/*from   ww  w .ja v a 2  s  .  c  o m*/

    stockProduct.setName(yahooQuote.getName());
    stockProduct.setHigh(BigDecimal.valueOf(yahooQuote.getHigh()));
    stockProduct.setLow(BigDecimal.valueOf(yahooQuote.getLow()));
    stockProduct.setDailyLatestChange(BigDecimal.valueOf(yahooQuote.getLastChange()));
    stockProduct.setDailyLatestChangePercent(BigDecimal.valueOf(yahooQuote.getLastChangePercent()));
    stockProduct.setDailyLatestValue(BigDecimal.valueOf(yahooQuote.getLast()));
    stockProduct.setPreviousClose(BigDecimal.valueOf(yahooQuote.getPreviousClose()));
    stockProduct.setOpen(BigDecimal.valueOf(yahooQuote.getOpen()));

    if (!StringUtils.isEmpty(yahooQuote.getExchange())) {
        stockProduct.setExchange(exchangeService.get(yahooQuote.getExchange()));
    }
    if (!StringUtils.isEmpty(yahooQuote.getCurrency())) {
        stockProduct.setCurrency(yahooQuote.getCurrency());
    }

    return stockProduct;
}

From source file:org.impotch.calcul.impot.cantonal.ge.pp.ConstructeurBaremeDeductionBeneficiaireRenteAVSAITest.java

@Test
public void baremeSeul2014() {
    BaremeConstantParTranche bareme = constructeur.construireBaremeSeul(2014);
    assertThat(bareme.calcul(BigDecimal.valueOf(50000))).isEqualTo("10078");
    assertThat(bareme.calcul(BigDecimal.valueOf(100000))).isEqualTo("0");
}

From source file:com.ocs.dynamo.ui.converter.BigDecimalConverter.java

@Override
public BigDecimal convertToModel(String value, Class<? extends BigDecimal> targetType, Locale locale) {
    // the original Vaadin code curiously returns a Double here and casts
    // that to a BigDecimal.
    // That is not correct, so we use this additional step here
    Number number = convertToNumber(value, BigDecimal.class, locale);
    return number == null ? null
            : BigDecimal.valueOf(number.doubleValue()).setScale(precision, RoundingMode.HALF_UP);
}

From source file:org.openmhealth.schema.domain.omh.UnitValue.java

public UnitValue(String unit, long value) {
    this(unit, BigDecimal.valueOf(value));
}