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:de.hybris.platform.integration.cis.tax.strategies.impl.DefaultCisCalculateExternalTaxesFallbackStrategyTest.java

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    defaultCisCalculateExternalTaxesFallbackStrategy = new DefaultCisCalculateExternalTaxesFallbackStrategy();
    defaultCisCalculateExternalTaxesFallbackStrategy.setConfigurationService(configurationService);
    given(configuration.getBigDecimal("cistax.taxCalculation.fallback.fixedpercentage", BigDecimal.valueOf(0D)))
            .willReturn(BigDecimal.valueOf(9.70d));
    given(configurationService.getConfiguration()).willReturn(configuration);

    final CurrencyModel currencyModel = mock(CurrencyModel.class);
    final AbstractOrderEntryModel entry = mock(AbstractOrderEntryModel.class);
    given(currencyModel.getIsocode()).willReturn("USD");
    given(abstractOrder.getCurrency()).willReturn(currencyModel);
    given(abstractOrder.getEntries()).willReturn(Collections.singletonList(entry));
    given(entry.getTotalPrice()).willReturn(Double.valueOf(100D));
    given(abstractOrder.getDeliveryCost()).willReturn(Double.valueOf(9.9D));
}

From source file:Main.java

/**
 * Subtract one positive Duration from another, larger positive Duration.
 * @param d1 The larger positive duration
 * @param d2 The smaller positive duration
 * @return The difference//from   w  ww .ja va  2s  .  co  m
 */
private static Duration subtractSmallerPositiveDurationFromLargerPositiveDuration(Duration d1, Duration d2) {
    BigDecimal s1 = fractionalSeconds(d1);
    BigDecimal s2 = fractionalSeconds(d2);
    BigDecimal extraSeconds = s1.subtract(s2);

    Duration strip1 = stripFractionalSeconds(d1);
    Duration strip2 = stripFractionalSeconds(d2);

    Duration stripResult = strip1.subtract(strip2);

    if (extraSeconds.compareTo(BigDecimal.ZERO) < 0) {
        stripResult = stripResult.subtract(DURATION_1_SECOND);
        extraSeconds = extraSeconds.add(BigDecimal.ONE);
    }

    BigDecimal properSeconds = BigDecimal.valueOf(stripResult.getSeconds()).add(extraSeconds);

    return FACTORY.newDuration(true, BigInteger.valueOf(stripResult.getYears()),
            BigInteger.valueOf(stripResult.getMonths()), BigInteger.valueOf(stripResult.getDays()),
            BigInteger.valueOf(stripResult.getHours()), BigInteger.valueOf(stripResult.getMinutes()),
            properSeconds);
}

From source file:net.sourceforge.fenixedu.domain.student.curriculum.CurriculumEntry.java

@Override
public BigDecimal getWeigthTimesGrade() {
    final String grade = getGradeValue();
    return StringUtils.isNumeric(grade)
            ? getWeigthForCurriculum().multiply(BigDecimal.valueOf(Double.valueOf(grade)))
            : null;//w  w w. j  a  v  a  2s.  c  o m
}

From source file:org.homiefund.test.dao.TransactionDAOTest.java

@Test
public void create() {
    Transaction tx = new Transaction();
    tx.setRevoked(false);//from   ww  w.  j  a v  a 2 s.  c  om
    tx.setDate(LocalDate.now());
    tx.setDescription(" create tessst ");
    tx.setOwner(userDAO.getById(1L));
    tx.setTransactionType(transactionTypeDAO.getById(4L));
    tx.setAmount(BigDecimal.valueOf(30.52));
    TransactionParticipant tp1 = new TransactionParticipant();
    tp1.setParticipant(userDAO.getById(1L));
    TransactionParticipant tp2 = new TransactionParticipant();
    tp2.setParticipant(userDAO.getById(2L));
    tx.setParticipants(new ArrayList<>(Arrays.asList(tp1, tp2)));

    Assert.assertNotNull(transactionDAO.create(tx));
    Assert.assertNotNull(tx.getId());

    BigDecimal half = tx.getAmount().divide(BigDecimal.valueOf(2L), new MathContext(2, RoundingMode.HALF_UP));
    tx.getParticipants().forEach(p -> Assert.assertEquals(half, p.getAmount()));
}

From source file:io.seldon.prediction.VariationPredictionStrategy.java

public SimplePredictionStrategy sample() {
    Integer hash = ThreadLocalRandom.current().nextInt();
    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  w w w  .j  av a 2s  . co m
    }
    return null;
}

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

@Test
public void shouldCreateWishListWithFormValues() {
    WishListForm form = WishListForm.newForm(messageSource);
    form.setBudget(BigDecimal.valueOf(150.50));
    form.setWishList(wishList());/*  www.ja v  a2  s.  com*/

    WishList wishList = form.buildWishList(owner());

    assertEquals("bob-my-list", wishList.getSlug());
    assertEquals("bob", wishList.getOwner());
    assertEquals("EUR150.50", wishList.getBudget().toString());
    assertEquals("public", wishList.getVisibility());
}

From source file:cherry.foundation.type.mybatis.SecureBigDecimalTypeHandlerTest.java

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

    int count = mapper.insert(record);
    assertThat(count, is(1));/*from   w  w  w.j a  v a 2s  .  c o  m*/
    assertThat(record.getId(), is(not(0)));

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

From source file:eu.europa.ec.grow.espd.xml.common.exporting.UblRequirementFactory.java

public static QuantityType buildYearType(Integer year) {
    if (year == null) {
        return null;
    }/*w  w w  . j  a va 2 s.  co m*/
    QuantityType quantityType = new QuantityType();
    quantityType.setValue(BigDecimal.valueOf(year));
    quantityType.setUnitCode("YEAR");
    return quantityType;
}

From source file:de.jfachwert.pruefung.NumberValidator.java

/**
 * Instanziert einen Validator, der prueft, ob ein Wert zwischen den
 * vorgegebenen Grenzen liegt./*ww w .j a va  2s .c  o m*/
 *
 * @param min untere Grenze
 * @param max obere Grenze
 */
public NumberValidator(long min, long max) {
    this(BigDecimal.valueOf(min), BigDecimal.valueOf(max));
}

From source file:pl.altkom.spring.spring.capgemini.core.dao.springdata.OrderDAOTest.java

@Test
public void testCreate() {

    User user = userDAO.findOne(1L);/*w w  w . j a v a  2s.  com*/

    if (user == null) {
        user = new User();
        user.setLogin("ala");
        user.setPassword("alalalal");
        userDAO.save(user);
    }

    List<OrderItem> items = new ArrayList<>();

    OrderItem item = new OrderItem();

    Product product;

    if (!productDAO.exists(1L)) {
        product = new Product();
        product.setColor("biay");
        product.setCurrency("PLN");
        product.setCost(BigDecimal.valueOf(123.55));
        productDAO.save(product);
    } else {
        //            product = new Product();
        //            product.setId(1L);
        product = productDAO.findOne(1L);
    }

    item.setProduct(product);
    item.setAmount(1);
    item.setDiscount(0);
    items.add(item);

    Order order = new Order();
    order.setOrderList(items);
    order.setUser(user);

    orderDAO.save(order);

}