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:io.coala.time.TimeSpan.java

/**
 * {@link TimeSpan} static factory method
 * /* www. j  a  v a  2 s  .c  o  m*/
 * @param temporal a JSR-310 {@link TemporalAmount}
 */
public static TimeSpan of(final TemporalAmount temporal) {
    return new TimeSpan(
            BigDecimal.valueOf(temporal.get(ChronoUnit.NANOS))
                    .add(BigDecimal.valueOf(temporal.get(ChronoUnit.MILLIS)).multiply(BigDecimal.TEN.pow(6))),
            Units.NANOS);
}

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

@Test
public void borneBaremeFortuneSupplementaire() {
    Bareme bareme = fournisseur.getBaremeFortuneSupplementaire(2015);
    assertThat(bareme.calcul(BigDecimal.valueOf(112138))).isEqualTo("0.00");
    assertThat(bareme.calcul(BigDecimal.valueOf(224276))).isEqualTo("12.60");
    assertThat(bareme.calcul(BigDecimal.valueOf(336414))).isEqualTo("28.00");
    assertThat(bareme.calcul(BigDecimal.valueOf(448551))).isEqualTo("61.65");
    assertThat(bareme.calcul(BigDecimal.valueOf(672828))).isEqualTo("134.55");
    assertThat(bareme.calcul(BigDecimal.valueOf(897103))).isEqualTo("252.30");
    assertThat(bareme.calcul(BigDecimal.valueOf(1121379))).isEqualTo("378.45");
    assertThat(bareme.calcul(BigDecimal.valueOf(1345654))).isEqualTo("557.85");
    assertThat(bareme.calcul(BigDecimal.valueOf(1682068))).isEqualTo("843.80");
    assertThat(bareme.calcul(BigDecimal.valueOf(3364137))).isEqualTo("2736.15");
}

From source file:net.eusashead.hateoas.springhalbuilder.model.Order.java

@Transient
@JsonIgnore/*from   w  ww  . ja  v  a2s . com*/
public BigDecimal getTotal() {
    double total = 0d;
    for (LineItem item : lineItems) {
        total += item.getSubTotal().doubleValue();
    }
    return BigDecimal.valueOf(total);
}

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

CollectionItemForm postedForm() {
    CollectionItem item = new CollectionItem();
    item.setItemId("2012-09-01_acme-123456");
    item.setAddedAt(date("2012-09-09"));
    item.setNotes("My notes");

    CollectionItemForm form = new CollectionItemForm();
    form.setPrice(BigDecimal.valueOf(100));
    form.setItem(item);//w ww  .  j a  v  a  2s.  c  o  m
    form.setRsSlug("acme-123456");

    return form;
}

From source file:net.eusashead.hateoas.hal.response.impl.HalResponseBuilderImplTest.java

@Test
public void testConstructRepresentation() throws Exception {

    // Create a HalGetResponseBuilder
    HalResponseBuilderImpl builder = new HalResponseBuilderImpl(representationFactory, request);

    // Create a response with a Representation
    ResponseEntity<Representation> response = builder.withProperty("string", "String value")
            .withProperty("date", new Date(123456789l)).withProperty("int", 34)
            .withProperty("decimal", BigDecimal.valueOf(123.32d)).withProperty("boolean", true)
            .withRepresentation("customer",
                    representationFactory.newRepresentation("/customer").withProperty("email",
                            "test@domain.com"))
            .etag(MODIFIED_DATE).lastModified(MODIFIED_DATE).expireIn(1000000).build();

    // Check the headers
    assertHeaders(response);/*from  w  ww.j  a  va2  s  .  co  m*/

    // Check the body
    Assert.assertEquals("/path/to/resource", response.getBody().getLinkByRel("self").getHref());
    Assert.assertEquals("String value", response.getBody().getValue("string").toString());
    Assert.assertEquals(new Date(123456789l).toString(), response.getBody().getValue("date").toString());
    Assert.assertEquals("34", response.getBody().getValue("int").toString());
    Assert.assertEquals("123.32", response.getBody().getValue("decimal").toString());
    Assert.assertEquals("true", response.getBody().getValue("boolean").toString());
    List<? extends ReadableRepresentation> customer = response.getBody().getResourcesByRel("customer");
    Assert.assertNotNull(customer);
    Assert.assertEquals(Integer.valueOf(1), Integer.valueOf(customer.size()));
    ReadableRepresentation cust = customer.get(0);
    Assert.assertEquals("test@domain.com", cust.getValue("email").toString());
}

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

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

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

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

}

From source file:com.roncoo.controller.BaseController.java

public BigDecimal getBigDecimal(String name, BigDecimal defaultValue) {
    String resultStr = getRequest().getParameter(name);
    if (resultStr != null) {
        try {//w  w  w .j  a  v  a2  s  .  co  m
            return BigDecimal.valueOf(Double.parseDouble(resultStr));
        } catch (Exception e) {
            return defaultValue;
        }
    }
    return defaultValue;
}

From source file:controllers.attachment.AttachUploadApp.java

/**
 * ?// w  ww.jav  a  2 s. c  o  m
 * @param filePart
 * @return
 */
public static ObjectNodeResult save(File sourceFile, String fileName, ObjectNodeResult result, User currentUser,
        String attachType) {
    StringBuffer sb = new StringBuffer(PROOF_UPLOAD_PATH);
    String date = dateFormat.format(new java.util.Date());
    sb.append("attachment");

    if (StringUtils.equals("suggestion", attachType)) {
        sb.append(File.separator).append("suggestion");
    } else if (StringUtils.equals("service", attachType)) {
        sb.append(File.separator).append("service");
    } else if (StringUtils.equals("require", attachType)) {
        sb.append(File.separator).append("require");
    } else if (StringUtils.equals("feedback", attachType)) {
        sb.append(File.separator).append("feedback");
    } else {
        sb.append(File.separator).append("industry");
    }
    sb.append(File.separator).append(date);

    //
    File path = new File(sb.toString());
    if (!path.exists()) {
        path.mkdirs();
    }
    //???cdn
    if (!path.exists()) {
        String str = "??";
        if (StringUtils.equals("service", attachType)) {
            str = "??";
        } else if (StringUtils.equals("require", attachType)) {
            str = "?";
        }
        return result.error(str);
    }

    String newFileName = getNewFileName(fileName);
    String uploadPath = sb.append(File.separator).append(newFileName).toString();
    File target = new File(uploadPath);
    BigDecimal sizeTemp = BigDecimal.valueOf(sourceFile.length());
    String suffixTemp = getSuffix(fileName);
    move(sourceFile, target);

    String relativePath = FEEDBACK_UPLOAD_RELATIVE_PATH;
    if (StringUtils.equals("suggestion", attachType)) {
        relativePath = SUGGESTION_UPLOAD_RELATIVE_PATH;
    } else if (StringUtils.equals("service", attachType)) {
        relativePath = SERVICE_UPLOAD_RELATIVE_PATH;
    } else if (StringUtils.equals("require", attachType)) {
        relativePath = REQUIRE_UPLOAD_RELATIVE_PATH;
    } else if (StringUtils.equals("industry", attachType)) {
        relativePath = INDUSTRY_UPLOAD_RELATIVE_PATH;
    }
    String relPath = new StringBuffer(relativePath).append(date).append("/").append(newFileName).toString();

    result.getObjectNode().put("path", relPath);
    result.getObjectNode().put("pathsource", Assets.at(relPath));
    // 
    String pathTemp = relPath;
    Attach attach = new AttachOfFeedback(fileName, pathTemp, suffixTemp, sizeTemp, new Date(),
            currentUser == null ? null : currentUser.getId(), currentUser == null ? "" : currentUser.getName(),
            false);
    if (StringUtils.equals("suggestion", attachType)) {
        attach = new AttachOfSuggestion(fileName, pathTemp, suffixTemp, sizeTemp, new Date(),
                currentUser == null ? null : currentUser.getId(),
                currentUser == null ? "" : currentUser.getName(), false);
    } else if (StringUtils.equals("service", attachType)) {
        attach = new AttachOfService(fileName, pathTemp, suffixTemp, sizeTemp, new Date(),
                currentUser == null ? null : currentUser.getId(),
                currentUser == null ? "" : currentUser.getName(), false);
    } else if (StringUtils.equals("require", attachType)) {
        attach = new AttachOfRequire(fileName, pathTemp, suffixTemp, sizeTemp, new Date(),
                currentUser == null ? null : currentUser.getId(),
                currentUser == null ? "" : currentUser.getName(), false);
    } else if (StringUtils.equals("industry", attachType)) {
        attach = new AttachOfIndustry(fileName, pathTemp, suffixTemp, sizeTemp, new Date(),
                currentUser == null ? null : currentUser.getId(),
                currentUser == null ? "" : currentUser.getName(), false);
    }
    attach.saveOrUpdate();
    result.getObjectNode().put("attachId", attach.id);
    result.getObjectNode().put("fileName", fileName);
    return result;
}

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

protected ConclusionProcessVersion(final RegistrationConclusionBean bean) {
    super();// ww w.  j  a  v  a  2 s  .  com
    super.setRootDomainObject(Bennu.getInstance());
    super.setCreationDateTime(new DateTime());
    super.setResponsible(AccessControl.getPerson());

    final YearMonthDay conclusion = bean.calculateConclusionDate();
    final Integer finalAverage = bean.calculateFinalAverage();
    final BigDecimal average = bean.calculateAverage();
    final Double ectsCredits = bean.calculateCredits();
    final ExecutionYear ingressionYear = bean.calculateIngressionYear();
    final ExecutionYear conclusionYear = bean.calculateConclusionYear();
    String[] args = {};

    if (finalAverage == null) {
        throw new DomainException("error.ConclusionProcessVersion.argument.must.not.be.null", args);
    }
    String[] args1 = {};
    if (average == null) {
        throw new DomainException("error.ConclusionProcessVersion.argument.must.not.be.null", args1);
    }
    String[] args2 = {};
    if (ectsCredits == null) {
        throw new DomainException("error.ConclusionProcessVersion.argument.must.not.be.null", args2);
    }
    String[] args3 = {};
    if (ingressionYear == null) {
        throw new DomainException("error.ConclusionProcessVersion.argument.must.not.be.null", args3);
    }
    String[] args4 = {};
    if (conclusionYear == null) {
        throw new DomainException("error.ConclusionProcessVersion.argument.must.not.be.null", args4);
    }

    super.setConclusionDate(conclusion.toLocalDate());
    super.setFinalAverage(finalAverage);
    super.setAverage(average);
    super.setCredits(BigDecimal.valueOf(ectsCredits));
    super.setCurriculum(bean.getCurriculumForConclusion().toString());
    super.setIngressionYear(ingressionYear);
    super.setConclusionYear(conclusionYear);
}

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

/**
 * {@link TimeSpan} static factory method
 * /*from  www.  j  ava 2 s. c  o  m*/
 * @param value a Joda {@link ReadableDuration}, e.g.
 *            {@link org.joda.time.Duration}
 */
public static TimeSpan of(final ReadableDuration value) {
    return new TimeSpan(BigDecimal.valueOf(value.getMillis()), Units.MILLIS);
}