List of usage examples for java.math BigDecimal divide
public BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
From source file:com.qcadoo.mes.technologies.controller.TechnologyMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFiles", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long technologyId = Long.parseLong(request.getParameter("techId")); Entity technology = dataDefinitionService .get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY) .get(technologyId);// www . j av a 2 s . c o m DataDefinition attachmentDD = dataDefinitionService.get(TechnologiesConstants.PLUGIN_IDENTIFIER, TechnologiesConstants.MODEL_TECHNOLOGY_ATTACHMENT); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null; while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(TechnologyAttachmentFields.ATTACHMENT, path); atchment.setField(TechnologyAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField(TechnologyAttachmentFields.TECHNOLOGY, technology); atchment.setField(TechnologyAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(TechnologyAttachmentFields.SIZE, size); attachmentDD.save(atchment); } } }
From source file:com.qcadoo.mes.cmmsMachineParts.controller.PlannedEventMultiUploadController.java
@ResponseBody @RequestMapping(value = "/multiUploadFilesForPlannedEvent", method = RequestMethod.POST) public void upload(MultipartHttpServletRequest request, HttpServletResponse response) { Long eventId = Long.parseLong(request.getParameter("eventId")); Entity event = dataDefinitionService .get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT) .get(eventId);/* w w w . jav a 2 s . c o m*/ DataDefinition attachmentDD = dataDefinitionService.get(CmmsMachinePartsConstants.PLUGIN_IDENTIFIER, CmmsMachinePartsConstants.MODEL_PLANNED_EVENT_ATTACHMENT); Iterator<String> itr = request.getFileNames(); MultipartFile mpf = null; while (itr.hasNext()) { mpf = request.getFile(itr.next()); String path = ""; try { path = fileService.upload(mpf); } catch (IOException e) { logger.error("Unable to upload attachment.", e); } if (exts.contains(Files.getFileExtension(path).toUpperCase())) { Entity atchment = attachmentDD.create(); atchment.setField(PlannedEventAttachmentFields.ATTACHMENT, path); atchment.setField(PlannedEventAttachmentFields.NAME, mpf.getOriginalFilename()); atchment.setField(PlannedEventAttachmentFields.PLANNED_EVENT, event); atchment.setField(PlannedEventAttachmentFields.EXT, Files.getFileExtension(path)); BigDecimal fileSize = new BigDecimal(mpf.getSize(), numberService.getMathContext()); BigDecimal divider = new BigDecimal(1024, numberService.getMathContext()); BigDecimal size = fileSize.divide(divider, L_SCALE, BigDecimal.ROUND_HALF_UP); atchment.setField(PlannedEventAttachmentFields.SIZE, size); atchment = attachmentDD.save(atchment); atchment.isValid(); } } }
From source file:easycare.load.util.db.loader.UserDataLoader.java
private void createUsersWithSubsetLocations(ContextOfCurrentLoad context, Organisation organisation, String organisationNumber) { List<Location> locations = organisation.activeLocations(); BigDecimal totalLocations = BigDecimal.valueOf(locations.size()); BigDecimal twoThirdLocations = totalLocations .divide(BigDecimal.valueOf(_THREE), _SIX, RoundingMode.HALF_EVEN).multiply(BigDecimal.valueOf(2)) .setScale(0, RoundingMode.CEILING); Location[] locationsToAdd = locations.subList(0, twoThirdLocations.intValue()).toArray(new Location[0]); List<Role> roles = newArrayList(seedData.getRole(ROLE_CLINICIAN)); buildUser(context, "remy" + organisationNumber, "Remy", "Roam", organisation, roles, organisationNumber, locationsToAdd);//from w w w.j a va2 s.c om }
From source file:com.autentia.tnt.businessobject.Project.java
public BigDecimal getCostPerProject() { BigDecimal total = new BigDecimal(0); Set<ProjectRole> roles = this.getRoles(); if (roles != null) { for (ProjectRole role : roles) { Set<Activity> activities = role.getActivities(); if (activities != null) { for (Activity activity : activities) { BigDecimal converse = new BigDecimal(activity.getUser().getCostPerHour()); BigDecimal div = new BigDecimal(activity.getDuration()); BigDecimal ret = div.multiply(converse); total = total.add(ret.divide(new BigDecimal(60), 2, BigDecimal.ROUND_HALF_UP));// += activity.getDuration() * activity.getUser().getCostPerHour()/ 60 ; }/*from ww w . j a v a 2 s . c o m*/ } } } return total; }
From source file:de.csdev.ebus.command.datatypes.ext.EBusTypeTime.java
@Override public byte[] encodeInt(Object data) throws EBusTypeException { IEBusType<BigDecimal> bcdType = types.getType(EBusTypeBCD.TYPE_BCD); IEBusType<BigDecimal> wordType = types.getType(EBusTypeWord.TYPE_WORD); IEBusType<BigDecimal> charType = types.getType(EBusTypeChar.TYPE_CHAR); Calendar calendar = null;/*from ww w .j av a2s . c om*/ byte[] result = new byte[this.getTypeLength()]; if (data instanceof EBusDateTime) { calendar = ((EBusDateTime) data).getCalendar(); } else if (data instanceof Calendar) { calendar = (Calendar) data; } // set date to 01.01.1970 calendar = (Calendar) calendar.clone(); calendar.set(1970, 0, 1); if (calendar != null) { if (StringUtils.equals(variant, DEFAULT)) { result = new byte[] { bcdType.encode(calendar.get(Calendar.SECOND))[0], bcdType.encode(calendar.get(Calendar.MINUTE))[0], bcdType.encode(calendar.get(Calendar.HOUR_OF_DAY))[0] }; } else if (StringUtils.equals(variant, SHORT)) { result = new byte[] { bcdType.encode(calendar.get(Calendar.MINUTE))[0], bcdType.encode(calendar.get(Calendar.HOUR_OF_DAY))[0] }; } else if (StringUtils.equals(variant, HEX)) { result = new byte[] { charType.encode(calendar.get(Calendar.SECOND))[0], charType.encode(calendar.get(Calendar.MINUTE))[0], charType.encode(calendar.get(Calendar.HOUR_OF_DAY))[0] }; } else if (StringUtils.equals(variant, HEX_SHORT)) { result = new byte[] { charType.encode(calendar.get(Calendar.MINUTE))[0], charType.encode(calendar.get(Calendar.HOUR_OF_DAY))[0] }; } else if (StringUtils.equals(variant, MINUTES) || StringUtils.equals(variant, MINUTES_SHORT)) { long millis = calendar.getTimeInMillis(); calendar.clear(); calendar.set(1970, 0, 1, 0, 0, 0); calendar.set(Calendar.MILLISECOND, 0); long millisMidnight = calendar.getTimeInMillis(); BigDecimal minutes = new BigDecimal(millis - millisMidnight); // milliseconds to minutes minutes = minutes.divide(BigDecimal.valueOf(1000 * 60), 0, RoundingMode.HALF_UP); // xxx minutes = minutes.divide(minuteMultiplier, 0, RoundingMode.HALF_UP); if (StringUtils.equals(variant, MINUTES_SHORT)) { result = charType.encode(minutes); } else { result = wordType.encode(minutes); } } } return result; }
From source file:com.autentia.intra.manager.billing.BillManager.java
/** * Account DAO *//from ww w. j a va 2 s . c o m */ public List<BillBreakDown> getAllBitacoreBreakDowns(Date start, Date end, Set<ProjectRole> roles, Set<ProjectCost> costes) { List<BillBreakDown> desgloses = new ArrayList<BillBreakDown>(); ActivityDAO activityDAO = ActivityDAO.getDefault(); ActivitySearch actSearch = new ActivitySearch(); actSearch.setBillable(new Boolean(true)); actSearch.setStartStartDate(start); actSearch.setEndStartDate(end); List<Activity> actividadesTotal = new ArrayList<Activity>(); Hashtable user_roles = new Hashtable(); for (ProjectRole proyRole : roles) { actSearch.setRole(proyRole); List<Activity> actividades = activityDAO.search(actSearch, new SortCriteria("startDate", false)); actividadesTotal.addAll(actividades); } for (Activity act : actividadesTotal) { String key = act.getRole().getId().toString() + act.getUser().getId().toString(); if (!user_roles.containsKey(key)) { Hashtable value = new Hashtable(); value.put("ROLE", act.getRole()); value.put("USER", act.getUser()); user_roles.put(key, value); } } Enumeration en = user_roles.keys(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); Hashtable pair = (Hashtable) user_roles.get(key); actSearch.setBillable(new Boolean(true)); actSearch.setStartStartDate(start); actSearch.setEndStartDate(end); ProjectRole pR = (ProjectRole) pair.get("ROLE"); User u = (User) pair.get("USER"); actSearch.setRole(pR); actSearch.setUser(u); List<Activity> actividadesUsuarioRol = activityDAO.search(actSearch, new SortCriteria("startDate", false)); BillBreakDown brd = new BillBreakDown(); brd.setConcept("Imputaciones (usuario - rol): " + u.getName() + " - " + pR.getName()); brd.setAmount(pR.getCostPerHour()); brd.setIva(new BigDecimal(ConfigurationUtil.getDefault().getIva())); BigDecimal unitsTotal = new BigDecimal(0); for (Activity act : actividadesUsuarioRol) { BigDecimal unitsActual = new BigDecimal(act.getDuration()); unitsActual = unitsActual.divide(new BigDecimal(60), 2, RoundingMode.HALF_UP); unitsTotal = unitsTotal.add(unitsActual); } brd.setUnits(unitsTotal); brd.setSelected(true); desgloses.add(brd); } for (ProjectCost proyCost : costes) { BillBreakDown brd = new BillBreakDown(); brd.setConcept("Coste: " + proyCost.getName()); brd.setUnits(new BigDecimal(1)); brd.setAmount(proyCost.getCost()); brd.setIva(new BigDecimal(ConfigurationUtil.getDefault().getIva())); brd.setSelected(true); desgloses.add(brd); } return desgloses; }
From source file:com.silverpeas.util.MetadataExtractor.java
private void computeMp4Duration(Metadata metadata, MovieHeaderBox movieHeaderBox) { BigDecimal duration = BigDecimal.valueOf(movieHeaderBox.getDuration()); if (duration.intValue() > 0) { BigDecimal divisor = BigDecimal.valueOf(movieHeaderBox.getTimescale()); // Duration duration = duration.divide(divisor, 10, BigDecimal.ROUND_HALF_DOWN); // get duration in ms duration = duration.multiply(BigDecimal.valueOf(1000)); metadata.add(XMPDM.DURATION, duration.toString()); }//from w w w . j a v a2 s . c o m }
From source file:org.libreplan.web.montecarlo.MonteCarloModel.java
@Override public Map<LocalDate, BigDecimal> calculateMonteCarlo(List<MonteCarloTask> tasks, int iterations, IDesktopUpdatesEmitter<Integer> iterationProgress) { MonteCarloCalculation monteCarloCalculation = new MonteCarloCalculation(copyOf(tasks), iterations, iterationProgress);//from ww w . j a v a2s . c o m Map<LocalDate, BigDecimal> monteCarloValues = monteCarloCalculation.doCalculation(); // Convert number of times to probability for (LocalDate key : monteCarloValues.keySet()) { BigDecimal times = monteCarloValues.get(key); BigDecimal probability = times.divide(BigDecimal.valueOf(iterations), 8, RoundingMode.HALF_UP); monteCarloValues.put(key, probability); } return monteCarloValues; }
From source file:services.kpi.PortfolioEntryAllocationProgressKpi.java
@Override public BigDecimal computeMain(IPreferenceManagerPlugin preferenceManagerPlugin, IScriptService scriptService, Kpi kpi, Long objectId) { BigDecimal timesheetedDays = computeAdditional1(preferenceManagerPlugin, scriptService, kpi, objectId) .setScale(2, RoundingMode.HALF_UP); BigDecimal forecastDays = computeAdditional2(preferenceManagerPlugin, scriptService, kpi, objectId); if (forecastDays.compareTo(BigDecimal.ZERO) > 0) { return timesheetedDays.divide(forecastDays, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100)); }//from w w w.ja va 2 s . co m return null; }
From source file:alfio.model.PriceContainerTest.java
@Test public void getFinalPriceInputVatNotIncluded() throws Exception { generateTestStream(PriceContainer.VatStatus.NOT_INCLUDED).forEach(p -> { PriceContainer priceContainer = p.getRight(); BigDecimal finalPrice = priceContainer.getFinalPrice(); Integer price = p.getLeft(); BigDecimal netPrice = MonetaryUtil.centsToUnit(price); BigDecimal vatAmount = finalPrice.subtract(netPrice); int result = MonetaryUtil.unitToCents(vatAmount .subtract(MonetaryUtil.calcVat(netPrice, priceContainer.getVatPercentageOrZero())).abs()); if (result >= 2) { BigDecimal calcVatPerc = vatAmount.divide(finalPrice, 5, RoundingMode.HALF_UP) .multiply(new BigDecimal("100.00")).setScale(2, RoundingMode.HALF_UP); fail(String.format("Expected percentage: %s, got %s, vat %s v. %s", calcVatPerc, priceContainer.getOptionalVatPercentage(), vatAmount, MonetaryUtil.calcVat(netPrice, priceContainer.getVatPercentageOrZero()))); }/*from w w w .jav a 2 s . com*/ }); }