List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:org.impotch.calcul.impot.cantonal.ne.pp.BaremeRevenu2012Test.java
@Test public void celibataire() { assertThat(bareme.calcul(BigDecimal.valueOf(100000))).isEqualTo("12300.00"); }
From source file:org.impotch.calcul.impot.cantonal.ne.pp.BaremeFortune2012Test.java
@Test public void borne() { assertThat(bareme.calcul(BigDecimal.valueOf(50000))).isEqualTo("0.00"); assertThat(bareme.calcul(BigDecimal.valueOf(200000))).isEqualTo("450.00"); assertThat(bareme.calcul(BigDecimal.valueOf(350000))).isEqualTo("1050.00"); assertThat(bareme.calcul(BigDecimal.valueOf(500000))).isEqualTo("1800.00"); }
From source file:com.willetinc.hadoop.mapreduce.dynamodb.BigDecimalSplitter.java
@Override void generateRangeKeySplits(Configuration conf, List<InputSplit> splits, Types hashKeyType, AttributeValue hashKeyValue, Types rangeKeyType, AttributeValue minRangeKeyValue, AttributeValue maxRangeKeyValue, int numRangeSplits) { BigDecimal numSplits = BigDecimal.valueOf(numRangeSplits); BigDecimal minVal = new BigDecimal(minRangeKeyValue.getN()); BigDecimal maxVal = new BigDecimal(maxRangeKeyValue.getN()); // Get all the split points together. List<BigDecimal> splitPoints = split(numSplits, minVal, maxVal); // Turn the split points into a set of intervals. BigDecimal start = splitPoints.get(0); for (int i = 1; i < splitPoints.size(); i++) { BigDecimal end = splitPoints.get(i); List<AttributeValue> rangeKeyValues = new ArrayList<AttributeValue>(); rangeKeyValues.add(new AttributeValue().withN(start.toString())); rangeKeyValues.add(new AttributeValue().withN(end.toString())); splits.add(new DynamoDBQueryInputFormat.DynamoDBQueryInputSplit(hashKeyType, hashKeyValue, rangeKeyType, rangeKeyValues, ComparisonOperator.BETWEEN)); // set start to end of last interval plus minimum positive value // in the case of DynamoDB Numbers it is 1.0^-38: // This is necessary to ensure we don't miss any values between // intervals. start = end.add(MIN_POSITIVE_VALUE); }// www.j a va2 s. c o m }
From source file:cherry.foundation.crypto.SecureBigDecimalEncoderTest.java
@Test public void testSecureBigDecimal() throws Exception { SecureBigDecimal.setEncoder(createSecureBigDecimalEncoder()); for (int i = 0; i < 100; i++) { BigDecimal plain = BigDecimal.valueOf(random.nextDouble()); SecureBigDecimal ss0 = SecureBigDecimal.plainValueOf(plain); assertThat(ss0.plain(), is(plain)); assertThat(ss0.crypto(), is(not(plain.toString()))); SecureBigDecimal ss1 = SecureBigDecimal.cryptoValueOf(ss0.crypto()); assertThat(ss1.plain(), is(plain)); assertThat(ss1.crypto(), is(ss0.crypto())); SecureBigDecimal ss2 = SecureBigDecimal.plainValueOf(ss1.plain()); assertThat(ss2.plain(), is(plain)); assertThat(ss2.crypto(), is(ss0.crypto())); SecureBigDecimal ss3 = SecureBigDecimal.cryptoValueOf(ss2.crypto()); assertThat(ss3.plain(), is(plain)); assertThat(ss3.crypto(), is(ss0.crypto())); }/*from www. ja va2s .co m*/ }
From source file:com.trenako.web.controllers.form.WishListFormTests.java
@Test public void shouldCreateNewWishListForms() { WishListForm form = WishListForm.newForm(messageSource); assertNotNull(form);//from w w w .j a va 2s. c o m assertEquals(new WishList(), form.getWishList()); assertEquals("{(public)=checked, (private)=}", form.getVisibilities().toString()); assertEquals(BigDecimal.valueOf(0), form.getBudget()); }
From source file:org.mayocat.shop.taxes.PriceWithTaxes.java
public PriceWithTaxes multiply(Long quantity) { return new PriceWithTaxes(this.incl().multiply(BigDecimal.valueOf(quantity)), this.excl().multiply(BigDecimal.valueOf(quantity)), this.vat().multiply(BigDecimal.valueOf(quantity))); }
From source file:com.anrisoftware.globalpom.measurement.RoundToSignificantFigures.java
/** * Rounds the value to the decimal places. * <p>//from ww w. ja v a 2 s .com * Algorithm takes from <a href= * "http://stackoverflow.com/questions/153724/how-to-round-a-number-to-n-decimal-places-in-java" * >How to round a number to n decimal places in Java * [stackoverflow.com]</a> * * @param value * the value. * * @param decimal * the decimal places. * * @return the rounded value. */ public static double roundToDecimal(double value, int decimal) { return BigDecimal.valueOf(value).setScale(decimal, ROUND_HALF_UP).doubleValue(); }
From source file:io.restassured.itest.java.BigDecimalITest.java
@Test public void floats_are_used_as_big_decimal_in_anonymous_list_with_numbers_when_configured_accordingly() { when().get("/anonymous_list_with_numbers").then().statusCode(HttpStatus.SC_OK).content("$", hasItems(100, 50, BigDecimal.valueOf(31.0))); }
From source file:io.interface21.domain.DataLoader.java
private Set<Question> buildSysQuestions() { return Stream.of(new Question[] { new MultipleChoiceQuestion("What is a discrete transformation algorithm?", 1, BigDecimal.valueOf(0L), Stream.of(new CheckableAnswerDefinition[] { new CheckableAnswerDefinition("Laplace", 1, BigDecimal.valueOf(0L)), new CheckableAnswerDefinition("Fourier", 2, BigDecimal.valueOf(0L)), new CheckableAnswerDefinition("Z", 3, BigDecimal.valueOf(100L)), new CheckableAnswerDefinition("Garett", 4, BigDecimal.valueOf(0L)) }) .collect(Collectors.toSet())) }) .collect(Collectors.toSet()); }
From source file:Main.java
/** * Compute e^x to a given scale by the Taylor series. * @param x the value of x// w w w . ja v a2s .co m * @param scale the desired scale of the result * @return the result value */ private static BigDecimal expTaylor(BigDecimal x, int scale) { BigDecimal factorial = BigDecimal.valueOf(1); BigDecimal xPower = x; BigDecimal sumPrev; // 1 + x BigDecimal sum = x.add(BigDecimal.valueOf(1)); // Loop until the sums converge // (two successive sums are equal after rounding). int i = 2; do { // x^i xPower = xPower.multiply(x).setScale(scale, BigDecimal.ROUND_HALF_EVEN); // i! factorial = factorial.multiply(BigDecimal.valueOf(i)); // x^i/i! BigDecimal term = xPower.divide(factorial, scale, BigDecimal.ROUND_HALF_EVEN); // sum = sum + x^i/i! sumPrev = sum; sum = sum.add(term); ++i; Thread.yield(); } while (sum.compareTo(sumPrev) != 0); return sum; }