List of usage examples for java.math BigDecimal valueOf
public static BigDecimal valueOf(double val)
From source file:org.devgateway.ocds.web.rest.controller.CorruptionRiskDashboardIndicatorsStatsController.java
@ApiOperation(value = "Percent of total projects eligible (denominator is total projects)") @RequestMapping(value = "/api/percentTotalProjectsEligibleByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") public List<DBObject> percentTotalProjectsEligibleByYear(final YearFilterPagingRequest filter) { //get the total projects eligible by year List<DBObject> totalEligibleProjects = totalEligibleProjectsByIndicatorTypeByYear(filter); //denominator total projects eligible by year List<DBObject> totalProjectsByYear = totalProjectsByYear(filter); totalEligibleProjects.forEach(e -> { findByYearAndTypeAndMonth(totalProjectsByYear, (Integer) e.get(Keys.YEAR), null, (Integer) e.get(Keys.MONTH)).forEach(f -> { e.put(Keys.PROJECT_COUNT, f.get(Keys.PROJECT_COUNT)); e.put(Keys.PERCENT,/* ww w . j a va 2 s . c om*/ (BigDecimal.valueOf((Integer) e.get(Keys.ELIGIBLE_PROJECT_COUNT)) .setScale(BIGDECIMAL_SCALE) .divide(BigDecimal.valueOf((Integer) f.get(Keys.PROJECT_COUNT)), BigDecimal.ROUND_HALF_UP) .multiply(ONE_HUNDRED))); }); }); return totalEligibleProjects; }
From source file:es.juntadeandalucia.panelGestion.negocio.vo.TaskVO.java
private void updateShapeProgress(BigDecimal numFeatures) { if (taskEntity.getState().getStatus() == Status.FINISHED) { finishState();/*from w w w . j a va2s . co m*/ } else { // gets current data int readLines = fileProcessor.getNumCurrentEntry(); int currentNumFeature = fileProcessor.getNumCurrentEntry(); // calculates the progress BigDecimal currentNumFeatureBD = BigDecimal.valueOf(currentNumFeature); double progress = currentNumFeatureBD.divide(numFeatures, 4, RoundingMode.HALF_UP) .multiply(BigDecimal.valueOf(100)).doubleValue(); // updates the task state taskEntity.getState().setReadLines(readLines); taskEntity.getState().setProgress(progress); // finishes when all bytes are read if (currentNumFeatureBD.longValue() == numFeatures.longValue()) { finishState(); } } }
From source file:pe.gob.mef.gescon.web.ui.PerfilMB.java
public void asignar(ActionEvent event) { try {/*from ww w.j av a 2 s . c o m*/ PoliticaPerfilService service = (PoliticaPerfilService) ServiceFinder.findBean("PoliticaPerfilService"); service.delete(this.getSelectedPerfil().getNperfilid()); LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB"); User user = loginMB.getUser(); for (int x = 0; x < this.listaPoliticas.getTarget().size(); x++) { TpoliticaPerfilId tpoliticaperfilid = new TpoliticaPerfilId(); tpoliticaperfilid.setNperfilid(this.getSelectedPerfil().getNperfilid()); tpoliticaperfilid .setNpoliticaid(BigDecimal.valueOf(Long.parseLong(this.listaPoliticas.getTarget().get(x)))); PoliticaPerfil politicaperfil = new PoliticaPerfil(); politicaperfil.setId(tpoliticaperfilid); politicaperfil.setDfechacreacion(new Date()); politicaperfil.setVusuariocreacion(user.getVlogin()); service.saveOrUpdate(politicaperfil); RequestContext.getCurrentInstance().execute("PF('asigDialog').hide();"); } } catch (Exception e) { log.error(e.getMessage()); e.printStackTrace(); } }
From source file:com.erudika.para.utils.Utils.java
/** * Round up a double using the "half up" method * @param d a double// w w w. ja va 2s . co m * @param scale the scale * @return a double */ public static double roundHalfUp(double d, int scale) { return BigDecimal.valueOf(d).setScale(scale, RoundingMode.HALF_UP).doubleValue(); }
From source file:dk.clanie.bitcoin.client.BitcoindClientIntegrationTest.java
@Test public void testSendFrom() throws Exception { StringResponse sendFrom = bc.sendFrom("clanie", "mwswEtw6t2ziSjsfip62FPg84NXGsJ5H2o", BigDecimal.valueOf(0.01d), 10, "Comment", "CommentTO"); print(sendFrom);/*w ww . j a v a 2 s . com*/ }
From source file:com.modelsolv.kaboom.serializer.SerializerTest.java
private TaxFiling buildTaxFiling() { TaxFiling filing = new TaxFiling(); filing.setFilingID("1234"); filing.setTaxpayer(buildPerson());// www.j a v a 2 s .co m filing.setCurrency("USD"); filing.setGrossIncome(BigDecimal.valueOf(115000)); filing.setJurisdiction("IRS"); filing.setPeriod(0); filing.setTaxLiability(BigDecimal.valueOf(18500)); filing.setYear(getXmlDate()); return filing; }
From source file:com.qsoft.components.gallery.utils.GalleryUtils.java
public static LocationDTOInterface getLocationDTO(Context context) throws IOException { LocationDTOInterface locationDTOInterface = null; Geocoder geocoder;/*from w w w. j a v a 2 s . co m*/ List<android.location.Address> addresses; geocoder = new Geocoder(context, Locale.getDefault()); android.location.Location location = LocationUtil.getCurrentLocationInformation(context); if (location != null) { addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); String address = addresses.get(0).getAddressLine(0); String street1 = addresses.get(0).getAddressLine(1); String street2 = addresses.get(0).getAddressLine(2); String city = addresses.get(0).getAddressLine(3); String country = addresses.get(0).getAddressLine(4); locationDTOInterface.setLongitude(BigDecimal.valueOf(location.getLongitude())); locationDTOInterface.setLatitude(BigDecimal.valueOf(location.getLatitude())); locationDTOInterface.setStreet(street1); } return locationDTOInterface; }
From source file:com.fanniemae.ezpie.common.StringUtilities.java
public static String formatAsNumber(double value) { BigDecimal valueOf = BigDecimal.valueOf(value); BigDecimal integerPart = BigDecimal.valueOf(valueOf.longValue()); BigDecimal fractional = valueOf.subtract(integerPart); String fraction = fractional.toPlainString(); int indexOfDot = fraction.indexOf('.') + 1; String sign = fraction.startsWith("-") ? "-" : ""; fraction = fraction.length() > indexOfDot ? fraction.substring(indexOfDot) : fraction; if (fraction.equals("0")) { return MessageFormat.format("{0}{1}", sign, integerPart.toPlainString(), fraction); } else {/*from w ww . ja v a 2s . c o m*/ return MessageFormat.format("{0}{1}.{2}", sign, integerPart.toPlainString(), fraction); } }