List of usage examples for java.math BigDecimal divide
public BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode)
From source file:org.egov.wtms.web.controller.application.MeterReadingController.java
private BigDecimal calculateDamagedMeterAverageDemand(final List<Installment> installmentList, final WaterConnectionDetails waterConnectionDetails) { BigDecimal totalAmount = BigDecimal.ZERO; int count = 0; Set<EgDemandDetails> demandDtlSet = null; BigDecimal meterDemandAmount = BigDecimal.ZERO; final EgDemand demand = waterTaxUtils.getCurrentDemand(waterConnectionDetails).getDemand(); if (demand != null) demandDtlSet = demand.getEgDemandDetails(); for (final Installment installment : installmentList) for (final EgDemandDetails demandDetail : demandDtlSet) if (demandDetail.getEgDemandReason().getEgInstallmentMaster().equals(installment)) { count++;//from w w w.ja v a 2 s . c om meterDemandAmount = meterDemandAmount.add(demandDetail.getAmount()); } if (count != 0) totalAmount = meterDemandAmount.divide(BigDecimal.valueOf(count), 0, BigDecimal.ROUND_HALF_UP); return totalAmount; }
From source file:org.projectforge.fibu.datev.EmployeeSalaryExportDao.java
private void addEmployeeRow(final ExportSheet sheet, final EmployeeDO employee, final BigDecimal numberOfWorkingDays, final BigDecimal totalDuration) { final PFUserDO user = userGroupCache.getUser(employee.getUserId()); final ExportRow row = sheet.addRow(); row.addCell(0, user.getFullname());/*from w w w.jav a 2 s . c om*/ // Wochenstunden row.addCell(1, employee.getWochenstunden(), "STUNDEN"); // Sollstunden: Wochenstunden * Arbeitstage / 5 Arbeitstage pro Woche Integer wochenstunden = employee.getWochenstunden(); if (wochenstunden == null) { wochenstunden = 0; } final BigDecimal soll = new BigDecimal(wochenstunden).multiply(numberOfWorkingDays) .divide(new BigDecimal(5), 2, RoundingMode.HALF_UP); row.addCell(2, soll, "STUNDEN"); // Iststunden final BigDecimal total = totalDuration.divide(new BigDecimal(3600000), 2, RoundingMode.HALF_UP); row.addCell(3, total, "STUNDEN"); // Differenz final BigDecimal differenz = total.subtract(soll); row.addCell(4, differenz, "STUNDEN"); }
From source file:org.projectforge.business.fibu.datev.EmployeeSalaryExportDao.java
private void addEmployeeRow(final ExportSheet sheet, final EmployeeDO employee, final BigDecimal numberOfWorkingDays, final BigDecimal totalDuration) { final PFUserDO user = getUserGroupCache().getUser(employee.getUserId()); final ExportRow row = sheet.addRow(); row.addCell(0, user.getFullname());//from w ww. j a va 2 s .c om // Wochenstunden row.addCell(1, employee.getWeeklyWorkingHours(), "STUNDEN"); // Sollstunden: Wochenstunden * Arbeitstage / 5 Arbeitstage pro Woche BigDecimal wochenstunden = employee.getWeeklyWorkingHours(); if (wochenstunden == null) { wochenstunden = BigDecimal.ZERO; } final BigDecimal soll = wochenstunden.multiply(numberOfWorkingDays).divide(new BigDecimal(5), 2, RoundingMode.HALF_UP); row.addCell(2, soll, "STUNDEN"); // Iststunden final BigDecimal total = totalDuration.divide(new BigDecimal(3600000), 2, RoundingMode.HALF_UP); row.addCell(3, total, "STUNDEN"); // Differenz final BigDecimal differenz = total.subtract(soll); row.addCell(4, differenz, "STUNDEN"); }
From source file:pyromaniac.Algorithm.BalzerOUCallFrequencyTable.java
/** * _calculate probability.// www . j av a 2 s .c o m * * @param mode the mode * @param segmentNumber the segment number * @return the BigDecimal [] of probabilities, all with scale of 10. */ private BigDecimal[] _calculateProbabilitiesHelper(int segmentNumber, int mode) { BigDecimal sd, mean, modeBD; //this multiplicative factor was taken from elsewhere... BigDecimal flowEffect = new BigDecimal("0.003").multiply(new BigDecimal(segmentNumber)).setScale(SCALE, BigDecimal.ROUND_HALF_UP); modeBD = new BigDecimal(mode); if (mode >= 6) { mean = new BigDecimal(mode).setScale(SCALE, BigDecimal.ROUND_HALF_UP); //standard deviation is 0.03 + effect of RefLen + effect of flow position sd = new BigDecimal("0.03494").add(mean.multiply(new BigDecimal("0.06856"))).add(flowEffect); } else { mean = new BigDecimal(this.normalDistParams.get(mode).getFirst()).setScale(SCALE, BigDecimal.ROUND_HALF_UP); sd = new BigDecimal(this.normalDistParams.get(mode).getSecond()).add(flowEffect).setScale(SCALE, BigDecimal.ROUND_HALF_UP); } NormalDistribution norm = new NormalDistribution(mean.doubleValue(), sd.doubleValue()); try { //due to rounding... //cumulative probability [X <= x] //so prob under is [X <= MODE - 0.51], and prob over is 1 - prob [X <= MODE + 0.49] (i.e. prob X > MODE + 0.49) BigDecimal lowerBound = modeBD.subtract(new BigDecimal(SUBTRACT_FOR_LB)).setScale(SCALE, BigDecimal.ROUND_HALF_UP); BigDecimal upperBound = modeBD.add(new BigDecimal(ADD_FOR_UB)).setScale(SCALE, BigDecimal.ROUND_HALF_UP); BigDecimal probLessThan = new BigDecimal(norm.cumulativeProbability(lowerBound.doubleValue())) .setScale(SCALE, BigDecimal.ROUND_HALF_UP); BigDecimal probMoreThan = new BigDecimal("1") .subtract(new BigDecimal(norm.cumulativeProbability(upperBound.doubleValue())).setScale(SCALE, BigDecimal.ROUND_HALF_UP)); BigDecimal probEqualTo = new BigDecimal("1").subtract(probLessThan).subtract(probMoreThan) .setScale(SCALE, BigDecimal.ROUND_HALF_UP); BigDecimal summed = probLessThan.add(probEqualTo).add(probMoreThan).setScale(SCALE, BigDecimal.ROUND_HALF_UP); if (!summed.equals(new BigDecimal("1").setScale(SCALE, BigDecimal.ROUND_HALF_UP))) { probLessThan = probLessThan.divide(summed, SCALE, BigDecimal.ROUND_HALF_UP); probMoreThan = probMoreThan.divide(summed, SCALE, BigDecimal.ROUND_HALF_UP); probEqualTo = probEqualTo.divide(summed, SCALE, BigDecimal.ROUND_HALF_UP); } BigDecimal[] probs = { probLessThan, probEqualTo, probMoreThan }; return probs; } catch (MathIllegalStateException me) { me.getStackTrace(); } return null; }
From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.Comparison.java
public void compareCASUV003WithCAS001() throws Exception { File infile;/* w w w.j av a 2 s . co m*/ infile = new File("C:/Work/Projects/MoSeS/Workspace/UV003.dat"); CASUV003DataHandler cASUV003DataHandler = new CASUV003DataHandler(infile); infile = new File("C:/Work/Projects/MoSeS/Workspace/CAS001.dat"); CAS001DataHandler tCAS001DataHandler = new CAS001DataHandler(infile); CASUV003DataRecord aCASUV003DataRecord; CAS001DataRecord aCAS001DataRecord; long difference; long maxDifference = Long.MIN_VALUE; long sumOfSquaredDifference = 0L; long totalDifference = 0L; long absoluteDifference = 0L; long totalAbsoluteDifference = 0L; long RecordID; long nRecords = cASUV003DataHandler.getNDataRecords(); for (RecordID = 0; RecordID < nRecords; RecordID++) { aCASUV003DataRecord = cASUV003DataHandler.getCASUV003DataRecord(RecordID); aCAS001DataRecord = tCAS001DataHandler.getCAS001DataRecord(RecordID); difference = (long) (aCASUV003DataRecord.getAllPeople() - aCAS001DataRecord.getAllPeople()); if (difference < 0) { absoluteDifference = difference * -1L; } sumOfSquaredDifference += (difference * difference); maxDifference = Math.max(maxDifference, difference); totalDifference += difference; totalAbsoluteDifference += absoluteDifference; } int scale = 100; int roundingMode = BigDecimal.ROUND_HALF_EVEN; BigDecimal nRecordsBigDecimal = new BigDecimal(nRecords); BigDecimal meanDifferenceBigDecimal = new BigDecimal(maxDifference).divide(nRecordsBigDecimal, scale, roundingMode); System.out.println("nRecords " + nRecords); System.out.println("meanDifferenceBigDecimal " + meanDifferenceBigDecimal.toString()); System.out.println("sumOfSquaredDifference " + sumOfSquaredDifference); System.out.println("maxDifference " + maxDifference); System.out.println("totalAbsoluteDifference " + totalAbsoluteDifference); System.out.println("totalDifference " + totalDifference); BigDecimal standardDeviationOfDifferenceBigDecimal = new BigDecimal("0"); BigDecimal differenceBigDecimal; for (RecordID = 0; RecordID < nRecords; RecordID++) { aCASUV003DataRecord = cASUV003DataHandler.getCASUV003DataRecord(RecordID); aCAS001DataRecord = tCAS001DataHandler.getCAS001DataRecord(RecordID); differenceBigDecimal = new BigDecimal( aCASUV003DataRecord.getAllPeople() - aCAS001DataRecord.getAllPeople()); standardDeviationOfDifferenceBigDecimal = differenceBigDecimal.multiply(differenceBigDecimal); } standardDeviationOfDifferenceBigDecimal = standardDeviationOfDifferenceBigDecimal .divide(nRecordsBigDecimal.subtract(BigDecimal.ONE), scale, roundingMode); standardDeviationOfDifferenceBigDecimal = Generic_BigDecimal.sqrt(standardDeviationOfDifferenceBigDecimal, scale, RoundingMode.HALF_EVEN); System.out.println("standardDeviationOfDifferenceBigDecimal " + standardDeviationOfDifferenceBigDecimal); }
From source file:org.kuali.kfs.module.bc.document.service.impl.BudgetConstructionReasonSummaryReportServiceImpl.java
protected void adjustPersonTotal(PersonTotalHolder totalsHolder) { Integer restatementCsfAmount = 0; if (totalsHolder.salaryPayMonth == 0 || totalsHolder.csfPayMonths == 0 || BigDecimal.ZERO.compareTo(totalsHolder.csfPercent) == 0 || totalsHolder.csfNormalMonths == 0) { restatementCsfAmount = 0;/*from w ww .j a v a 2 s. c om*/ } else { BigDecimal salaryMonthPercent = new BigDecimal( totalsHolder.salaryNormalMonths * 1.0 / totalsHolder.salaryPayMonth); BigDecimal salaryFteQuantity = totalsHolder.salaryPercent.multiply(salaryMonthPercent); BigDecimal csfMonthpercent = new BigDecimal( totalsHolder.csfNormalMonths * 1.0 / totalsHolder.csfPayMonths); BigDecimal csfFteQuantity = totalsHolder.csfPercent.multiply(csfMonthpercent); BigDecimal restatementCsfPercent = salaryFteQuantity.divide(csfFteQuantity, 6, BigDecimal.ROUND_HALF_UP); BigDecimal csfAmount = new BigDecimal(totalsHolder.csfAmount); restatementCsfAmount = csfAmount.multiply(restatementCsfPercent).setScale(0, BigDecimal.ROUND_HALF_UP) .intValue(); } if (totalsHolder.salaryPayMonth == 0) { totalsHolder.salaryFte = BigDecimal.ZERO; } else { BigDecimal salaryFte = totalsHolder.salaryPercent.multiply( new BigDecimal(totalsHolder.salaryNormalMonths * 1.0 / (totalsHolder.salaryPayMonth * 100.0))); totalsHolder.salaryFte = BudgetConstructionReportHelper.setDecimalDigit(salaryFte, 5, false); } if (totalsHolder.salaryPayMonth != totalsHolder.csfPayMonths) { if (totalsHolder.csfPayMonths == 0) { restatementCsfAmount = 0; } else { BigDecimal amount = new BigDecimal( restatementCsfAmount * totalsHolder.salaryPayMonth * 1.0 / totalsHolder.csfPayMonths); restatementCsfAmount = BudgetConstructionReportHelper.setDecimalDigit(amount, 0, false).intValue(); } } totalsHolder.csfAmount = restatementCsfAmount; totalsHolder.amountChange = totalsHolder.salaryAmount - totalsHolder.csfAmount; if (totalsHolder.csfAmount != 0) { totalsHolder.percentChange = BudgetConstructionReportHelper.calculatePercent(totalsHolder.amountChange, totalsHolder.csfAmount); } else { totalsHolder.percentChange = BigDecimal.ZERO; } if (totalsHolder.curToInt != 0 && totalsHolder.curToInt != -1 && totalsHolder.curToInt != totalsHolder.salaryAmount.intValue() || totalsHolder.curFteInt != 0 && totalsHolder.curFteInt != -1.00 && totalsHolder.curFteInt != totalsHolder.salaryFte.doubleValue()) { totalsHolder.tiFlag = BCConstants.Report.PLUS; } else { totalsHolder.tiFlag = BCConstants.Report.BLANK; } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java
private DepartmentSummaryElement getDepartmentSummaryResume(final ExecutionSemester executionSemester, final Department department) { DepartmentSummaryElement departmentSummariesElement = new DepartmentSummaryElement(department, executionSemester);//from w w w .j av a 2s . c om Set<ExecutionCourse> allDepartmentExecutionCourses = getDepartmentExecutionCourses(department, executionSemester); if (allDepartmentExecutionCourses != null) { LocalDate today = new LocalDate(); LocalDate oneWeekBeforeToday = today.minusDays(8); for (ExecutionCourse executionCourse : allDepartmentExecutionCourses) { int instanceLessonsTotal[] = { 0, 0, 0 }; for (Shift shift : executionCourse.getAssociatedShifts()) { getInstanceLessonsTotalsByShift(shift, instanceLessonsTotal, oneWeekBeforeToday); } BigDecimal result = BigDecimal.valueOf(0); BigDecimal numberOfLessonInstances = BigDecimal.valueOf(instanceLessonsTotal[0]); BigDecimal numberOfLessonInstancesWithSummary = BigDecimal.valueOf(0); BigDecimal percentageOfLessonsWithNotTaughtSummary = BigDecimal.valueOf(0); BigDecimal numberOfLessonInstancesWithNotTaughtSummary = BigDecimal.valueOf(0); if (instanceLessonsTotal[0] == 0) { continue; } if (instanceLessonsTotal[1] != 0) { numberOfLessonInstancesWithSummary = BigDecimal.valueOf(instanceLessonsTotal[1]); result = numberOfLessonInstancesWithSummary .divide(numberOfLessonInstances, 3, BigDecimal.ROUND_CEILING) .multiply(BigDecimal.valueOf(100)); } if (instanceLessonsTotal[2] != 0) { numberOfLessonInstancesWithNotTaughtSummary = BigDecimal.valueOf(instanceLessonsTotal[2]); percentageOfLessonsWithNotTaughtSummary = numberOfLessonInstancesWithNotTaughtSummary .divide(numberOfLessonInstances, 3, BigDecimal.ROUND_CEILING) .multiply(BigDecimal.valueOf(100)); } SummaryControlCategory resumeClassification = getResumeClassification(result); Map<SummaryControlCategory, List<ExecutionCourseSummaryElement>> departmentResumeMap = departmentSummariesElement .getExecutionCoursesResume(); List<ExecutionCourseSummaryElement> executionCoursesSummary = null; if (departmentResumeMap == null) { departmentResumeMap = new HashMap<SummaryControlCategory, List<ExecutionCourseSummaryElement>>(); executionCoursesSummary = new ArrayList<ExecutionCourseSummaryElement>(); ExecutionCourseSummaryElement executionCourseSummaryElement = new ExecutionCourseSummaryElement( executionCourse, numberOfLessonInstances, numberOfLessonInstancesWithSummary, result, numberOfLessonInstancesWithNotTaughtSummary, percentageOfLessonsWithNotTaughtSummary); executionCoursesSummary.add(executionCourseSummaryElement); departmentResumeMap.put(resumeClassification, executionCoursesSummary); departmentSummariesElement.setExecutionCoursesResume(departmentResumeMap); } else { executionCoursesSummary = departmentResumeMap.get(resumeClassification); if (executionCoursesSummary == null) { executionCoursesSummary = new ArrayList<ExecutionCourseSummaryElement>(); ExecutionCourseSummaryElement executionCourseSummaryElement = new ExecutionCourseSummaryElement( executionCourse, numberOfLessonInstances, numberOfLessonInstancesWithSummary, result, numberOfLessonInstancesWithNotTaughtSummary, percentageOfLessonsWithNotTaughtSummary); executionCoursesSummary.add(executionCourseSummaryElement); departmentResumeMap.put(resumeClassification, executionCoursesSummary); } else { ExecutionCourseSummaryElement executionCourseSummaryElement = new ExecutionCourseSummaryElement( executionCourse, numberOfLessonInstances, numberOfLessonInstancesWithSummary, result, numberOfLessonInstancesWithNotTaughtSummary, percentageOfLessonsWithNotTaughtSummary); executionCoursesSummary.add(executionCourseSummaryElement); } } } } return departmentSummariesElement; }
From source file:org.gradoop.flink.datagen.transactions.foodbroker.config.FoodBrokerConfig.java
/** * Adds positive or negative influence to the start value, depending on the * quality of the master data objects.//from w w w . j ava2 s. c om * * @param influencingMasterDataQuality list of influencing master data quality * @param higherIsBetter true if positiv influence shall be added, negative * influence otherwise * @param influence influence value to be added to the start value * @param startValue the start value * @return aggregated start value */ protected Float getValue(List<Float> influencingMasterDataQuality, boolean higherIsBetter, Float influence, Float startValue) { Float value = startValue; BigDecimal influenceCount = BigDecimal.ZERO; for (float quality : influencingMasterDataQuality) { // check quality value of the masterdata and adjust the result value influenceCount = influenceCount.add(BigDecimal.valueOf(quality)); } if (influenceCount.compareTo(BigDecimal.ZERO) > 0) { influenceCount = influenceCount.setScale(2, BigDecimal.ROUND_HALF_UP); // normalize the quality value influenceCount = influenceCount.divide(BigDecimal.valueOf(influencingMasterDataQuality.size()), 8, RoundingMode.HALF_UP); // subtract the avg normal, for standard config it is 0.5 influenceCount = influenceCount.subtract(getAvgNormal()); // if the normalized value is greater than the avg if (influenceCount.compareTo(BigDecimal.ZERO) == 1) { // calculate how much times the value is greater than the difference // between the avg normal value and the lowest good value influenceCount = influenceCount.divide( BigDecimal.valueOf(getQualityGood()).subtract(getAvgNormal()).abs(), 0, BigDecimal.ROUND_HALF_UP); // if the normalized value is LOWER than the avg } else if (influenceCount.compareTo(BigDecimal.ZERO) == -1) { // calculate how much times the value is smaller than the difference // between the avg normal value and the lowest normal value influenceCount = influenceCount.divide( BigDecimal.valueOf(getQualityNormal()).subtract(getAvgNormal()).abs(), 0, BigDecimal.ROUND_HALF_UP); } } influence *= influenceCount.intValue(); if (higherIsBetter) { value += influence; } else { value -= influence; } return value; }
From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.statistics.StatisticsAction.java
private Spreadsheet generateSpreadSheet(final SortedMap<Object, BigDecimal> sumMap, final SortedMap<Object, BigDecimal> medianMap, final SortedMap<Object, BigDecimal> averageMap, final SortedMap<Object, BigDecimal> minsMap, final SortedMap<Object, BigDecimal> maxsMap) { final Spreadsheet spreadsheet = new Spreadsheet("Estatsticas"); spreadsheet.setHeader("Estado"); spreadsheet.setHeader("Soma"); spreadsheet.setHeader("Mediana Tempo (em dias)"); spreadsheet.setHeader("Mdia Tempo (em dias)"); spreadsheet.setHeader("Tempo Mnimo (em dias)"); spreadsheet.setHeader("Tempo Mximo (em dias)"); final SortedSet<Object> types = new TreeSet<Object>(); types.addAll(sumMap.keySet());/*ww w .ja v a 2 s . com*/ types.addAll(medianMap.keySet()); types.addAll(averageMap.keySet()); BigDecimal DAYS_CONST = new BigDecimal(1000 * 3600 * 24); for (final Object type : types) { final BigDecimal sum = sumMap.get(type); final BigDecimal median = medianMap.get(type); final BigDecimal average = averageMap.get(type); final BigDecimal min = minsMap.get(type); final BigDecimal max = maxsMap.get(type); final Row row = spreadsheet.addRow(); row.setCell(((IPresentableEnum) type).getLocalizedName()); row.setCell(sum == null ? "0" : sum.toString()); row.setCell(median == null ? "" : median.divide(DAYS_CONST, 2, BigDecimal.ROUND_HALF_UP).toString()); row.setCell(average == null ? "" : average.divide(DAYS_CONST, 2, BigDecimal.ROUND_HALF_UP).toString()); row.setCell(min == null ? "" : min.divide(DAYS_CONST, 2, BigDecimal.ROUND_HALF_UP).toString()); row.setCell(max == null ? "" : max.divide(DAYS_CONST, 2, BigDecimal.ROUND_HALF_UP).toString()); } return spreadsheet; }
From source file:org.kuali.kfs.module.bc.document.service.impl.SalarySettingServiceImpl.java
/** * @see org.kuali.kfs.module.bc.document.service.SalarySettingService#calculateFteQuantity(java.lang.Integer, java.lang.Integer, * java.math.BigDecimal)//from w w w .j ava 2s .c o m */ public BigDecimal calculateFteQuantity(Integer payMonth, Integer fundingMonth, BigDecimal requestedTimePercent) { LOG.debug("calculateFteQuantity() start"); if (payMonth == null || fundingMonth == null || requestedTimePercent == null) { return BigDecimal.ZERO; } BigDecimal payMonthAsDecimal = BigDecimal.valueOf(payMonth); BigDecimal fundingMonthAsDecimal = BigDecimal.valueOf(fundingMonth); BigDecimal fundingMonthPercent = fundingMonthAsDecimal.divide(payMonthAsDecimal, 5, BigDecimal.ROUND_HALF_UP); BigDecimal fteQuantity = requestedTimePercent.multiply(fundingMonthPercent) .divide(KFSConstants.ONE_HUNDRED.bigDecimalValue()); return fteQuantity.setScale(5, BigDecimal.ROUND_HALF_UP); }