Example usage for java.math BigDecimal BigDecimal

List of usage examples for java.math BigDecimal BigDecimal

Introduction

In this page you can find the example usage for java.math BigDecimal BigDecimal.

Prototype

public BigDecimal(long val) 

Source Link

Document

Translates a long into a BigDecimal .

Usage

From source file:cherry.foundation.type.converter.SecureBigDecimalConverterTest.java

@Test
public void testConvert() {
    for (int i = 0; i < 100; i++) {
        BigDecimal plain = new BigDecimal(random.nextDouble());
        String crypto = SecureBigDecimal.plainValueOf(plain).crypto();
        assertThat(cs.convert(crypto, SecureBigDecimal.class).plain(), is(plain));
    }//w w  w.  jav  a  2  s .  co  m
}

From source file:mobile.vo.rns.RequireVO.java

public static RequireVO create(Require po) {
    ObjectMapper objectMapper = JackJsonUtil.getMapperInstance(false);
    RequireVO vo = new RequireVO();

    vo.setId(po.getId());/*from  w w  w . ja  va2 s. co  m*/
    vo.setOwnerUserId(po.getOwner().getId());
    vo.setOwnerUsername(po.getOwner().getUserNameOrEmail());
    vo.setOwnerAvatar_70(po.getOwner().getAvatar(70));

    Expert ownerExpert = po.getOwner().getExperts().iterator().next();
    vo.setOwnerJob(ownerExpert.job);
    vo.setOwnerCountry(ownerExpert.country);

    SkillTag industry = po.getIndustry();
    if (null != industry) {
        vo.setIndustryId(industry.getId());
        vo.setIndustryName(industry.getTagName());
    }

    vo.setTitle(po.getTitle());
    vo.setInfo(po.getInfo());

    if (null == po.getBudget()) {
        vo.setBudget("-1"); // -1 - ?
    } else {
        vo.setBudget(new BigDecimal(po.getBudget()).setScale(1, BigDecimal.ROUND_HALF_UP).toString());
    }

    vo.setCreateDate(new DateTime(po.getCreateDate()).toString("yyyy-MM-dd HH:mm:ss"));

    if (StringUtils.isNotBlank(po.getTags())) {
        try {
            @SuppressWarnings("unchecked")
            List<String> readValue = objectMapper.readValue(po.getTags(), List.class);
            vo.setTags(readValue);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    return vo;
}

From source file:net.groupbuy.template.method.CurrencyMethod.java

@SuppressWarnings("rawtypes")
public Object exec(List arguments) throws TemplateModelException {
    if (arguments != null && !arguments.isEmpty() && arguments.get(0) != null
            && StringUtils.isNotEmpty(arguments.get(0).toString())) {
        boolean showSign = false;
        boolean showUnit = false;
        if (arguments.size() == 2) {
            if (arguments.get(1) != null) {
                showSign = Boolean.valueOf(arguments.get(1).toString());
            }//  w  w  w .  j av  a 2s.  c  om
        } else if (arguments.size() > 2) {
            if (arguments.get(1) != null) {
                showSign = Boolean.valueOf(arguments.get(1).toString());
            }
            if (arguments.get(2) != null) {
                showUnit = Boolean.valueOf(arguments.get(2).toString());
            }
        }
        Setting setting = SettingUtils.get();
        BigDecimal amount = new BigDecimal(arguments.get(0).toString());
        String price = setting.setScale(amount).toString();
        if (showSign) {
            price = setting.getCurrencySign() + price;
        }
        if (showUnit) {
            price += setting.getCurrencyUnit();
        }
        return new SimpleScalar(price);
    }
    return null;
}

From source file:com.benfante.minimark.blo.ResultCalculationBo.java

/**
 * Calculate the evaluation of an assessment. Moreover it stores the result
 * in the assessment filling and sets the evaluated flag.
 *
 * @param assessment The assessment to evaluate.
 * @return The evaluation/* w  w  w  .  j  a va2  s  .com*/
 */
public BigDecimal calculate(AssessmentFilling assessment) {
    BigDecimal result = new BigDecimal("0.00");
    final Assessment assessmentDef = assessment.getAssessment();
    evaluateAllQuestions(assessment, assessmentDef.getEvaluationClosedMinimumEvaluation());
    String evaluationType = assessmentDef.getEvaluationType();
    if (evaluationType == null || Assessment.EVALUATION_SIMPLE_SUM.equals(evaluationType)) {
        result = calculateSimpleSum(assessment);
    } else if (Assessment.EVALUATION_NORMALIZED_SUM.equals(evaluationType)) {
        result = calculateNormalizedSum(assessment, assessmentDef.getEvaluationMaxValue());
    }
    assessment.setEvaluationResult(result);
    assessment.setEvaluated(Boolean.TRUE);
    return result;
}

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

@Test
public void baremeSource() {
    Bareme bareme = fournisseur.getBaremeFortune(2011);
    assertEquals("Pour 1000000 francs", new BigDecimal("2994.50"), bareme.calcul(new BigDecimal("1000000")));
    bareme = fournisseur.getBaremeFortuneSupplementaire(2011);
    assertEquals("Pour 1000000 francs", new BigDecimal("310.70"), bareme.calcul(new BigDecimal("1000000")));

}

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

@Test
public void baremeSource() {
    Bareme bareme = fournisseur.getBaremeRevenu(2011);
    assertEquals("Pour 17753 francs", new BigDecimal("9.90"), bareme.calcul(new BigDecimal("17753")));
    assertEquals("Pour 17700 francs", new BigDecimal("5.70"), bareme.calcul(new BigDecimal("17700")));
    assertEquals("Pour 17629 francs", new BigDecimal("0.00"), bareme.calcul(new BigDecimal("17629")));
    assertEquals("Pour 17630 francs", new BigDecimal("0.10"), bareme.calcul(new BigDecimal("17630")));
}

From source file:com.startup.musicstore.test.repository.CreditCardRepositoryTest.java

@Test(enabled = true)
public void createCreditCard() {
    // *** (i) Create The Entity
    //Get The Repository Object 
    creditCardRepository = ctx.getBean(CreditCardRepository.class);
    //Create the Credit card Object using the Builder Design Pattern with ID. It will be generated
    // USE BUILDER PATTERN FOR CREATING ALL YOUR ENTITIES
    CreditCard creditCard = new CreditCard.Builder("5555-555-555-55555").balance(new BigDecimal(200.00))
            .expiryDate(new Date()).nameOnCreditCard("John Dole").build();
    //SAVE THE CREDIT CARD OBJECT 
    creditCardRepository.save(creditCard);
    // STORE THE ID FOR LATER USE
    id = creditCard.getId();//from w  w  w.  j a v a2 s  .  c om
    // ASSERT THAT THE OBJECT IS SAVED
    Assert.assertNotNull(creditCard);

}

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

@Test
public void baremeSource() {
    Bareme bareme = fournisseur.getBaremeRevenu(2010);
    assertEquals("Pour 17753 francs", new BigDecimal("18.10"), bareme.calcul(new BigDecimal("17753")));
}

From source file:es.logongas.encuestas.modelo.resultados.InferenciaEstadistica.java

public InferenciaEstadistica(EstadisticaDescriptiva estadisticaDescriptiva, BigDecimal nivelConfianza,
        int numDecimals) {
    this.numDecimals = numDecimals;
    if (nivelConfianza.compareTo(BigDecimal.ZERO) <= 0) {
        throw new IllegalArgumentException("El nivelConfianza debe ser mayor que 0");
    }/*  w  w  w.j a va 2s  . c  o m*/
    if (nivelConfianza.compareTo(BigDecimal.ONE) >= 0) {
        throw new IllegalArgumentException("El nivelConfianza debe ser menor que 1");
    }

    TDistribution tDistribution = new TDistribution(estadisticaDescriptiva.getNumMuestras() - 1);
    double t = tDistribution.inverseCumulativeProbability(nivelConfianza.doubleValue());
    BigDecimal delta = new BigDecimal(t * (estadisticaDescriptiva.getDesviacionEstandar().doubleValue()
            / Math.sqrt(estadisticaDescriptiva.getNumMuestras())));

    BigDecimal min = estadisticaDescriptiva.getMedia().subtract(delta).setScale(this.numDecimals,
            RoundingMode.HALF_UP);
    BigDecimal max = estadisticaDescriptiva.getMedia().add(delta).setScale(this.numDecimals,
            RoundingMode.HALF_UP);
    intervaloConfianzaMedia = new IntervaloConfianza(min, max, nivelConfianza);

}

From source file:be.ceau.chart.datapoint.ScatterDataPoint.java

public ScatterDataPoint setX(double x) {
    this.x = new BigDecimal(String.valueOf(x));
    return this;
}