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:com.streamsets.pipeline.stage.it.AllSdcTypesIT.java

@Parameterized.Parameters(name = "type({0})")
public static Collection<Object[]> data() throws Exception {
    return Arrays.asList(new Object[][] { { Field.create(Field.Type.BOOLEAN, true), true, Types.BOOLEAN, true },
            { Field.create(Field.Type.CHAR, 'A'), true, Types.VARCHAR, "A" },
            { Field.create(Field.Type.BYTE, (byte) 0x00), false, 0, null },
            { Field.create(Field.Type.SHORT, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.INTEGER, 10), true, Types.INTEGER, 10 },
            { Field.create(Field.Type.LONG, 10), true, Types.BIGINT, 10L },
            { Field.create(Field.Type.FLOAT, 1.5), true, Types.FLOAT, 1.5 },
            { Field.create(Field.Type.DOUBLE, 1.5), true, Types.DOUBLE, 1.5 },
            { Field.create(Field.Type.DATE, new Date(116, 5, 13)), true, Types.DATE, new Date(116, 5, 13) },
            { Field.create(Field.Type.DATETIME, date), true, Types.VARCHAR, datetimeFormat.format(date) },
            { Field.create(Field.Type.TIME, date), true, Types.VARCHAR, timeFormat.format(date) },
            { Field.create(Field.Type.DECIMAL, BigDecimal.valueOf(1.5)), true, Types.DECIMAL,
                    new BigDecimal(BigInteger.valueOf(15), 1, new MathContext(2, RoundingMode.FLOOR)) },
            { Field.create(Field.Type.STRING, "StreamSets"), true, Types.VARCHAR, "StreamSets" },
            { Field.create(Field.Type.BYTE_ARRAY, new byte[] { (byte) 0x00 }), true, Types.BINARY,
                    new byte[] { (byte) 0x00 } },
            { Field.create(Field.Type.MAP, Collections.emptyMap()), false, 0, null },
            { Field.create(Field.Type.LIST, Collections.emptyList()), false, 0, null },
            { Field.create(Field.Type.LIST_MAP, new LinkedHashMap<>()), false, 0, null }, });
}

From source file:io.seldon.recommendation.VariationTestingClientStrategy.java

public ClientStrategy sample(String userId) {
    Integer hash = MurmurHash.hash(userId.getBytes(), HASH_SEED);
    int sample = Math.abs(hash % 100) + 1;
    BigDecimal sampleDec = BigDecimal.valueOf(sample).divide(BigDecimal.valueOf(100));
    for (Range range : strategyMap.keySet()) {
        if (range.containsNumber(sampleDec)) {
            return strategyMap.get(range);
        }/*from   www . j a v a 2  s .c  o  m*/
    }
    return null;
}

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

@Test
public void couple() {
    //TypeArrondi arrond = TypeArrondi.CINQ_CTS;
    assertThat(baremeCouple.calcul(BigDecimal.valueOf(revenu))).isEqualTo(impot);
}

From source file:io.coala.time.Rate.java

/**
 * {@link Rate} constructor for "natural" polymorphic Jackson bean
 * deserialization//from   ww w .  ja v a  2  s  . c o  m
 * 
 * @see com.fasterxml.jackson.databind.deser.BeanDeserializer
 */
public Rate(final int rate) {
    this(BigDecimal.valueOf(rate), SI.HERTZ);
}

From source file:es.tid.fiware.rss.service.RSSModelsManagerTest.java

/**
 * Method to insert data before test.//from   w  ww .j  a v a2 s .co  m
 * 
 * @throws Exception
 *             from dbb
 */
@Before
public void setUp() throws Exception {
    databaseLoader.cleanInsert("dbunit/CREATE_DATATEST_TRANSACTIONS.xml", true);
    rssModel = new RSSModel();
    rssModel.setAppProviderId(appProviderId);
    rssModel.setProductClass("productClassTest");
    rssModel.setPercRevenueShare(BigDecimal.valueOf(40));
}

From source file:churashima.action.manage.ExpensesAction.java

@Execute(validator = false)
public String index() {

    Date date = new Date();
    if (StringUtils.isEmpty(expensesForm.strDate)) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        expensesForm.strDate = sdf.format(date);
    }/* w w w. j a  va 2  s.  c  o m*/

    Calendar cal = Calendar.getInstance();
    cal.setTime(date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);

    ExpensesDao expensesDao = SingletonS2Container.getComponent(ExpensesDao.class);
    List<Expenses> expensesList = expensesDao.selectForSearch(null, null, null, null, null, null, null, null,
            new Timestamp(cal.getTimeInMillis()));

    expensesForm.expensesList = expensesList;

    //       expensesForm.subjectId = null;
    expensesForm.place = null;
    expensesForm.name = null;
    expensesForm.price = BigDecimal.valueOf(0);
    expensesForm.comment = null;
    expensesForm.isExcludeTax = null;

    SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class);
    expensesForm.subjectList = subjectDao.selectForSearch(null, Const.STATUS_STARTING);

    return "expenses.jsp";
}

From source file:com.epages.checkout.CartApiTest.java

private void givenProduct() {
    product = productRefRepository.saveAndFlush(new ProductRef(1L, "some", BigDecimal.valueOf(50)));
}

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

@Test
public void calculCotisationAi() {
    assertThat(calculateur2008.calculCotisationAi(BigDecimal.valueOf(100000))).isEqualTo("1400.00");
}

From source file:com.jive.myco.seyren.core.service.notification.HubotNotificationServiceTest.java

@Test
public void checkingOutTheHappyPath() {

    String seyrenUrl = clientDriver.getBaseUrl() + "/seyren";

    when(mockSeyrenConfig.getHubotUrl()).thenReturn(clientDriver.getBaseUrl() + "/hubot");
    when(mockSeyrenConfig.getBaseUrl()).thenReturn(seyrenUrl);

    Check check = new Check().withEnabled(true).withName("check-name").withState(AlertType.ERROR);

    Subscription subscription = new Subscription().withType(SubscriptionType.HUBOT).withTarget("123,456");

    Alert alert = new Alert().withTarget("the.target.name").withValue(BigDecimal.valueOf(12))
            .withWarn(BigDecimal.valueOf(5)).withError(BigDecimal.valueOf(10)).withFromType(AlertType.WARN)
            .withToType(AlertType.ERROR);

    List<Alert> alerts = Arrays.asList(alert);

    BodyCapture<JsonNode> bodyCapture = new JsonBodyCapture();

    clientDriver.addExpectation(/*from  w w w  .  j a va2s.  co m*/
            onRequestTo("/hubot/seyren/alert").withMethod(Method.POST).capturingBodyIn(bodyCapture),
            giveResponse("Thanks for letting me know", "text/plain"));

    service.sendNotification(check, subscription, alerts);

    JsonNode node = bodyCapture.getContent();

    assertThat(node, hasJsonPath("$.seyrenUrl", is(seyrenUrl)));
    assertThat(node, hasJsonPath("$.check.name", is("check-name")));
    assertThat(node, hasJsonPath("$.check.state", is("ERROR")));
    assertThat(node, hasJsonPath("$.alerts", hasSize(1)));
    assertThat(node, hasJsonPath("$.alerts[0].target", is("the.target.name")));
    assertThat(node, hasJsonPath("$.alerts[0].value", is(12)));
    assertThat(node, hasJsonPath("$.alerts[0].warn", is(5)));
    assertThat(node, hasJsonPath("$.alerts[0].error", is(10)));
    assertThat(node, hasJsonPath("$.alerts[0].fromType", is("WARN")));
    assertThat(node, hasJsonPath("$.alerts[0].toType", is("ERROR")));
    assertThat(node, hasJsonPath("$.rooms", hasSize(2)));
    assertThat(node, hasJsonPath("$.rooms[0]", is("123")));
    assertThat(node, hasJsonPath("$.rooms[1]", is("456")));

    verify(mockSeyrenConfig).getHubotUrl();
    verify(mockSeyrenConfig).getBaseUrl();

}

From source file:com.oreilly.springdata.neo4j.AbstractIntegrationTest.java

@Before
public void setUp() throws Exception {
    dave = template.save(new Customer("Dave", "Matthews", "dave@dmband.com"));
    template.save(new Customer("Carter", "Beauford", "carter@dmband.com"));
    template.save(new Customer("Boyd", "Tinsley", "boyd@dmband.com"));
    final Country usa = template.save(new Country("US", "United States"));
    template.save(new Address("27 Broadway", "New York", usa));
    iPad = template.save(new Product("iPad", "Apple tablet device").withPrice(BigDecimal.valueOf(499D)));
    mbp = template.save(new Product("MacBook Pro", "Apple notebook").withPrice(BigDecimal.valueOf(1299D)));
    final Order order = new Order(dave);
    order.add(iPad, 2);/*  w  ww.ja va  2 s .c o  m*/
    order.add(mbp, 1);
    template.save(order);
}