List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:engine.Pi.java
/** * Compute the value, in radians, of the arctangent of * the inverse of the supplied integer to the specified * number of digits after the decimal point. The value * is computed using the power series expansion for the * arc tangent://from ww w . j av a2s. com * * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 + * (x^9)/9 ... */ public static BigDecimal arctan(int inverseX, int scale) { BigDecimal result, numer, term; BigDecimal invX = BigDecimal.valueOf(inverseX); BigDecimal invX2 = BigDecimal.valueOf(inverseX * inverseX); numer = BigDecimal.ONE.divide(invX, scale, roundingMode); result = numer; int i = 1; do { numer = numer.divide(invX2, scale, roundingMode); int denom = 2 * i + 1; term = numer.divide(BigDecimal.valueOf(denom), scale, roundingMode); if ((i % 2) != 0) { result = result.subtract(term); } else { result = result.add(term); } i++; } while (term.compareTo(BigDecimal.ZERO) != 0); return result; }
From source file:org.osmsurround.ae.osm.OsmConvertService.java
public OsmRoot createOsmNode() { OsmRoot osm = of.createOsmRoot(); osm.setVersion(BigDecimal.valueOf(0.6)); osm.setGenerator("Amenity Editor"); return osm; }
From source file:de.jfachwert.math.Bruch.java
/** * Legt die uebergebene Gleitkommazahl als Bruch an. * * @param number Dezimalzahl, z.B. 0.5/*from ww w.j a v a 2 s . c om*/ */ public Bruch(double number) { this(BigDecimal.valueOf(number)); }
From source file:enterprises.orbital.evekit.model.corporation.sync.ESICorporationIndustryJobSync.java
@SuppressWarnings("RedundantThrows") @Override/*from w w w . ja v a 2s. com*/ protected void processServerData(long time, ESIAccountServerResult<List<GetCorporationsCorporationIdIndustryJobs200Ok>> data, List<CachedData> updates) throws IOException { // Add and record orders for (GetCorporationsCorporationIdIndustryJobs200Ok next : data.getData()) { IndustryJob nextJob = new IndustryJob(next.getJobId(), next.getInstallerId(), next.getFacilityId(), next.getLocationId(), next.getActivityId(), next.getBlueprintId(), next.getBlueprintTypeId(), next.getBlueprintLocationId(), next.getOutputLocationId(), next.getRuns(), BigDecimal.valueOf(nullSafeDouble(next.getCost(), 0D)).setScale(2, RoundingMode.HALF_UP), nullSafeInteger(next.getLicensedRuns(), 0), nullSafeFloat(next.getProbability(), 0F), nullSafeInteger(next.getProductTypeId(), 0), next.getStatus().toString(), next.getDuration(), next.getStartDate().getMillis(), next.getEndDate().getMillis(), nullSafeDateTime(next.getPauseDate(), new DateTime(new Date(0L))).getMillis(), nullSafeDateTime(next.getCompletedDate(), new DateTime(new Date(0L))).getMillis(), nullSafeInteger(next.getCompletedCharacterId(), 0), nullSafeInteger(next.getSuccessfulRuns(), 0)); updates.add(nextJob); } }
From source file:org.impotch.calcul.impot.cantonal.ge.pp.avant2010.BaremeRevenuSeul2000Test.java
@Test public void test() { assertThat(bareme.calcul(BigDecimal.valueOf(revenu))).isEqualTo(impot); }
From source file:org.impotch.calcul.assurancessociales.CalculCotisationAvsAiApgIndependantTest.java
@Test public void calculCotisationApg() { assertThat(calculateur2008.calculCotisationApg(BigDecimal.valueOf(100000))).isEqualTo("300.00"); }
From source file:edu.usu.sdl.openstorefront.common.util.Convert.java
public static BigDecimal toBigDecimal(Object data, BigDecimal defaultDecimal) { if (data != null) { try {/*ww w . j a v a2s . c o m*/ if (data instanceof Integer) { return BigDecimal.valueOf(((Integer) data).doubleValue()); } else if (data instanceof String) { return new BigDecimal(data.toString()); } else if (data instanceof BigDecimal) { return (BigDecimal) data; } else if (data instanceof BigInteger) { return BigDecimal.valueOf(((BigInteger) data).longValue()); } else if (data instanceof Number) { return BigDecimal.valueOf(((Number) data).longValue()); } } catch (NumberFormatException e) { return defaultDecimal; } } return null; }
From source file:com.jive.myco.seyren.core.service.notification.HttpNotificationServiceTest.java
@Test public void checkingOutTheHappyPath() { String seyrenUrl = clientDriver.getBaseUrl() + "/seyren"; when(mockSeyrenConfig.getGraphiteUrl()).thenReturn(clientDriver.getBaseUrl() + "/graphite"); when(mockSeyrenConfig.getBaseUrl()).thenReturn(seyrenUrl); Check check = new Check().withEnabled(true).withName("check-name").withTarget("statsd.metric.name") .withState(AlertType.ERROR).withWarn(BigDecimal.ONE).withError(BigDecimal.TEN); Subscription subscription = new Subscription().withType(SubscriptionType.HTTP) .withTarget(clientDriver.getBaseUrl() + "/myendpoint/thatdoesstuff"); 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. ja v a 2 s. c o m*/ onRequestTo("/myendpoint/thatdoesstuff").withMethod(Method.POST).capturingBodyIn(bodyCapture), giveResponse("success", "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("$.preview", Matchers.startsWith("<br />"))); assertThat(node, hasJsonPath("$.preview", containsString(check.getTarget()))); verify(mockSeyrenConfig).getGraphiteUrl(); verify(mockSeyrenConfig).getBaseUrl(); }
From source file:com.trenako.web.controllers.WishListsControllerTests.java
@Test public void shouldRenderCreationFormForWishLists() { String viewName = controller.newWishList(model); assertEquals("wishlist/new", viewName); WishListForm form = (WishListForm) model.get("newForm"); assertNotNull(form);/*from www. jav a 2 s . c o m*/ assertNotNull("Visibility list is empty", form.getVisibilities()); assertEquals(new WishList(), form.getWishList()); assertEquals(BigDecimal.valueOf(0), form.getBudget()); }
From source file:org.impotch.calcul.impot.cantonal.ge.pp.Baremes2015Test.java
@Test public void borneBaremeFortune() { Bareme bareme = fournisseur.getBaremeFortune(2015); assertThat(bareme.calcul(BigDecimal.valueOf(112138))).isEqualTo("196.25"); assertThat(bareme.calcul(BigDecimal.valueOf(224276))).isEqualTo("448.55"); assertThat(bareme.calcul(BigDecimal.valueOf(336414))).isEqualTo("756.95"); assertThat(bareme.calcul(BigDecimal.valueOf(448551))).isEqualTo("1093.35"); assertThat(bareme.calcul(BigDecimal.valueOf(672828))).isEqualTo("1822.25"); assertThat(bareme.calcul(BigDecimal.valueOf(897103))).isEqualTo("2607.20"); assertThat(bareme.calcul(BigDecimal.valueOf(1121379))).isEqualTo("3448.25"); assertThat(bareme.calcul(BigDecimal.valueOf(1345654))).isEqualTo("4345.35"); assertThat(bareme.calcul(BigDecimal.valueOf(1682068))).isEqualTo("5775.10"); }