List of usage examples for java.math BigDecimal toString
@Override
public String toString()
From source file:com.ccserver.digital.service.LOSService.java
private CustomerInfoType getCustomerInfoType(CreditCardApplicationDTO dto) { CustomerInfoType customerInfo = new CustomerInfoType(); customerInfo.setFirstName(dto.getFirstName()); customerInfo.setLastName(dto.getLastName()); customerInfo.setMidName(dto.getMiddleName()); customerInfo.setFullName(getFullName(dto)); customerInfo.setCustomerType(getConfiguration("LOS_PCARD", "NORMAL")); IDInfoType idInfo = new IDInfoType(); switch (dto.getTypeOfID()) { case Passport: idInfo.setIDType(getConfiguration("LOS_PV", "PV")); break;// ww w . j ava2 s. co m case NationalID: idInfo.setIDType(getConfiguration("LOS_IDTYPE_IC", "IC")); break; } idInfo.setIDNo(dto.getPassportNumber()); idInfo.setIDIssueDate(dateToXMLGregorianCalendar(dto.getDateOfIssue())); if (dto.getPlaceOfIssue() != null) { idInfo.setIDIssueBy(dto.getPlaceOfIssue().getCode()); } CountryDTO citizenship = dto.getCitizenship(); if (citizenship != null) { customerInfo.setNationality(citizenship.getIsoCode()); idInfo.setCountry(citizenship.getCode()); if (!"+84".equalsIgnoreCase(citizenship.getCode())) { idInfo.setIDIssueBy(getConfiguration("LOS_ID_ISSUE_BY_FOREIGNER", "Cuc quan ly xuat nhap canh")); } } customerInfo.getIDInfo().add(idInfo); if (!StringUtils.isEmpty(dto.getLicenseNumber())) { IDInfoType licenseNumberInfo = new IDInfoType(); licenseNumberInfo.setIDType(getConfiguration("LOS_IDTYPE_BSL", "BSL")); licenseNumberInfo.setIDNo(dto.getLicenseNumber()); customerInfo.getIDInfo().add(licenseNumberInfo); } ContactInfoType contactInfo = new ContactInfoType(); PhoneInfoType phoneInfoMobile = new PhoneInfoType(); phoneInfoMobile.setPhoneNo(getPhoneNumber(dto.getMobile())); phoneInfoMobile.setPhoneType(getConfiguration("LOS_PHONETYPE", "mobiphone")); contactInfo.getPhoneInfo().add(phoneInfoMobile); // TODO check with UI design (aLy) PhoneInfoType workPhone = new PhoneInfoType(); workPhone.setPhoneNo(getPhoneNumber(dto.getMobile())); workPhone.setPhoneType(getConfiguration("LOS_WORKPHONETYPE", "workphone")); contactInfo.getPhoneInfo().add(workPhone); AddressDTO currentAddressDto = dto.getCurrentAddress(); if (dto.isCurrentIsPermanent()) { currentAddressDto = dto.getPermanentAddress(); } String totalMonthsLiving = getDurationFormat(dto.getMonthsOfLiving(), dto.getYearsOfLiving()); LocalDateTime startLivingTime = LocalDateTime.now().minusMonths(Integer.parseInt(totalMonthsLiving)); AddressInfoType currentAddress = getAddressInfoType(currentAddressDto); currentAddress.setStartDate(dateToXMLGregorianCalendar(startLivingTime)); currentAddress.setDuration(totalMonthsLiving); currentAddress.setIsPermanent( dto.isCurrentIsPermanent() ? getConfiguration("LOS_YES", "Y") : getConfiguration("LOS_NO", "N")); contactInfo.setAddressInfo(currentAddress); contactInfo.setMailAddress(dto.getEmail()); AddressInfoType permanentAddress = getAddressInfoType(dto.getPermanentAddress()); permanentAddress.setStartDate(dateToXMLGregorianCalendar(startLivingTime)); permanentAddress.setDuration(totalMonthsLiving); permanentAddress.setIsPermanent(dto.isCurrentIsPermanent() ? "Y" : "N"); contactInfo.setPermanentAddressInfo(permanentAddress); customerInfo.setContactInfo(contactInfo); switch (dto.getGender()) { case Male: customerInfo.setGender(getConfiguration("LOS_MALE", "M")); break; case Female: customerInfo.setGender(getConfiguration("LOS_FEMALE", "F")); break; } customerInfo.setBirthday(dateToXMLGregorianCalendar(dto.getDob())); SelectionListDTO education = dto.getEducation(); if (education != null) { customerInfo.setEducation(education.getCode()); } SelectionListDTO maritalStatus = dto.getMaritalStatus(); if (maritalStatus != null) { customerInfo.setMaritalStatus(maritalStatus.getCode()); } if (dto.getNumberOfChildren() != null) { customerInfo.setNumberOfChildren(dto.getNumberOfChildren().toString()); } customerInfo.setSector(getConfiguration("LOS_SECTOR", "1001")); customerInfo.setSegments(getConfiguration("LOS_KHCN", "SEG1")); // pass FT because risk from los customerInfo.setEmploymentStatus(getConfiguration("LOS_FT", "FT")); // customerInfo.setEmploymentStatus(dto.getTypeOfEmployement().equals(TypeOfEmployement.Business) // ? "BO" : "FT"); FrequencyInfoType incomeFrequency = new FrequencyInfoType(); incomeFrequency.setType(getConfiguration("LOS_IC", "INC2")); incomeFrequency.setFrequency(getConfiguration("LOS_FREQUENCY", "M")); AmountType amountType = new AmountType(); BigDecimal monthlyIncome = dto.getMonthlyIncome(); if (monthlyIncome != null) { amountType.setAmount(monthlyIncome.toString()); } amountType.setCurrency(getConfiguration("LOS_VND", "VND")); incomeFrequency.setAmount(amountType); incomeFrequency.setMonthlyAmount(amountType); incomeFrequency.setTotalMonthlyAmount(amountType); customerInfo.setIncomeFrequency(incomeFrequency); FrequencyInfoType expenseFrequency = new FrequencyInfoType(); expenseFrequency.setType(getConfiguration("LOS_FREQUENCY_TYPE", "EXP1")); expenseFrequency.setFrequency(getConfiguration("LOS_FREQUENCY", "M")); AmountType exAmountType = new AmountType(); exAmountType.setAmount(dto.getMonthlyExpenses() + ""); exAmountType.setCurrency(getConfiguration("LOS_VND", "VND")); expenseFrequency.setAmount(exAmountType); expenseFrequency.setMonthlyAmount(exAmountType); expenseFrequency.setTotalMonthlyAmount(exAmountType); customerInfo.setExpenseFrequency(expenseFrequency); FrequencyInfoType netFrequency = new FrequencyInfoType(); AmountType netAmountType = new AmountType(); if (monthlyIncome != null) { netAmountType.setAmount(monthlyIncome.subtract( dto.getMonthlyExpenses() != null ? dto.getMonthlyExpenses() : BigDecimal.valueOf(0L)) + ""); } netFrequency.setAmount(netAmountType); netFrequency.setMonthlyAmount(netAmountType); netFrequency.setTotalMonthlyAmount(netAmountType); customerInfo.setNetFrequency(netFrequency); customerInfo.setGreenCard(String.valueOf(convertBooleanToString(dto.isHaveGreenCard()))); customerInfo.setTinNumber(StringUtils.isEmpty(dto.getTinNumber()) ? "0" : dto.getTinNumber()); customerInfo.setGLPNumber(dto.getGlpNumber()); return customerInfo; }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** CAST(FLOAT AS VARCHAR). */ public static String toString(float x) { if (x == 0) { return "0E0"; }/* w w w . ja v a 2s . co m*/ BigDecimal bigDecimal = new BigDecimal(x, MathContext.DECIMAL32).stripTrailingZeros(); final String s = bigDecimal.toString(); return s.replaceAll("0*E", "E").replace("E+", "E"); }
From source file:org.apache.calcite.runtime.SqlFunctions.java
/** CAST(DOUBLE AS VARCHAR). */ public static String toString(double x) { if (x == 0) { return "0E0"; }// w ww .ja va 2 s . c o m BigDecimal bigDecimal = new BigDecimal(x, MathContext.DECIMAL64).stripTrailingZeros(); final String s = bigDecimal.toString(); return s.replaceAll("0*E", "E").replace("E+", "E"); }
From source file:org.openvpms.esci.adapter.map.invoice.InvoiceMapperImpl.java
/** * Verfies that a tax subtotal matches that expected, and has a valid rate. * * * @param subtotal the subtotal * @param expectedTaxAmount the expected tax amount * @param amount the line extension amount * @param rates the tax rates * @param parent the parent element * @throws ESCIAdapterException if the subtotal is invalid *///w ww. j a va 2 s . c o m protected void checkTax(UBLTaxSubtotal subtotal, BigDecimal expectedTaxAmount, BigDecimal amount, TaxRates rates, UBLType parent) { if (subtotal != null) { BigDecimal taxAmount = subtotal.getTaxAmount(); if (expectedTaxAmount.compareTo(taxAmount) != 0) { ErrorContext context = new ErrorContext(subtotal, "TaxAmount"); throw new ESCIAdapterException(ESCIAdapterMessages.ublInvalidValue(context.getPath(), context.getType(), context.getID(), expectedTaxAmount.toString(), taxAmount.toString())); } UBLTaxCategory category = subtotal.getTaxCategory(); BigDecimal rate = checkTaxCategory(category, rates); BigDecimal divisor = BigDecimal.valueOf(100); if (taxAmount.compareTo(BigDecimal.ZERO) != 0) { BigDecimal calc = MathRules.divide(amount.multiply(rate), divisor, 2); if (calc.compareTo(expectedTaxAmount) != 0) { ErrorContext context = new ErrorContext(subtotal, "TaxTotal/TaxAmount"); throw new ESCIAdapterException(ESCIAdapterMessages.ublInvalidValue(context.getPath(), context.getType(), context.getID(), calc.toString(), expectedTaxAmount.toString())); } } } else if (expectedTaxAmount.compareTo(BigDecimal.ZERO) != 0) { ErrorContext context = new ErrorContext(parent, "TaxTotal"); throw new ESCIAdapterException( ESCIAdapterMessages.ublElementRequired(context.getPath(), context.getType(), context.getID())); } }
From source file:it.govpay.web.rs.dars.monitoraggio.incassi.IncassiHandler.java
@Override public String getSottotitolo(Incasso entry, BasicBD bd) { StringBuilder sb = new StringBuilder(); String causale = entry.getCausale(); BigDecimal importo = entry.getImporto() != null ? entry.getImporto() : BigDecimal.ZERO; sb.append(Utils.getInstance(this.getLanguage()).getMessageWithParamsFromResourceBundle( this.nomeServizio + ".label.sottotitolo", causale, importo.toString() + "")); return sb.toString(); }
From source file:is.idega.idegaweb.egov.gumbo.licenses.SendLicenseFeeClaimHandler.java
public void execute(ExecutionContext executionContext) throws Exception { CaseProcInstBind bind = getCasesBPMDAO() .getCaseProcInstBindByProcessInstanceId(executionContext.getProcessInstance().getId()); if (bind == null) { LOGGER.warning("Case and process instance bind can not be found by process instance ID: " + executionContext.getProcessInstance().getId()); return;/* w ww . ja v a 2s .c o m*/ } Case theCase = getCaseBusiness().getCase(bind.getCaseId()); if (theCase == null) { return; } String processDefinitionName = executionContext.getProcessDefinition().getName(); String shipID = (String) executionContext.getVariable("string_vesselRegistryNr"); String ssn = (String) executionContext.getVariable("string_ownerSocialNumber"); String subType = null; BigDecimal fishingLicenseKey = null; // create license if ("Grasleppa".equals(processDefinitionName)) { subType = (String) executionContext.getVariable("string_typeOfFishingLicense"); Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); Timestamp toStamp = (Timestamp) executionContext.getVariable("date_endOfFishing"); String areaID = (String) executionContext.getVariable("string_fishingAreaId"); IWTimestamp from = new IWTimestamp(fromStamp); IWTimestamp to = new IWTimestamp(toStamp); fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, to, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } else if ("Strandveidileyfi".equals(processDefinitionName)) { CheckReplyTypeUser quotaCheck = getWSClient().getQuotaTransferCheckForShip(shipID); boolean isValid = quotaCheck.getIsok().intValue() > 0; if (!isValid) { throw new GumboProcessException("Error creating fishing license"); } Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); String postalCode = (String) executionContext.getVariable("string_ownerPostCode"); String areaID = null; CodeTypeUser areaInfo = getWSClient().getFishingAreaStrandveidi(postalCode); if (areaInfo == null) { throw new GumboProcessException("Error creating fishing license"); } Map<BigDecimal, VeidileyfagerdTypeUser> areas = getWSClient().getStrandveidiAreas(); if (areas != null && !areas.isEmpty()) { for (Iterator iterator = areas.keySet().iterator(); iterator.hasNext();) { VeidileyfagerdTypeUser item = areas.get(iterator.next()); if (item.getKodiSvaedis().equals(areaInfo.getCode())) { areaID = item.getVlyfId().toString(); break; } } } if (areaID == null) { throw new GumboProcessException("Error creating fishing license"); } IWTimestamp from = new IWTimestamp(fromStamp); fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, null, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } else if ("Draganotaveidi".equals(processDefinitionName)) { Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); IWTimestamp from = new IWTimestamp(fromStamp); IWTimestamp to = new IWTimestamp(from); to.setMonth(8); to.setDay(31); if (to.isEarlierThan(from)) { to.addYears(1); } String areaID = null; CodeTypeUser areaInfo = getWSClient().getFishingAreaForDraganotaveidi(shipID); Map<BigDecimal, VeidileyfagerdTypeUser> areas = getWSClient().getDragnotaAreas(from.getDate()); if (areas != null && !areas.isEmpty()) { for (Iterator iterator = areas.keySet().iterator(); iterator.hasNext();) { VeidileyfagerdTypeUser item = areas.get(iterator.next()); if (item.getKodiSvaedis().equals(areaInfo.getCode())) { areaID = item.getVlyfId().toString(); break; } } } if (areaID == null) { throw new GumboProcessException("Error creating fishing license"); } fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, to, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } else if ("FishingLicense".equals(processDefinitionName)) { subType = (String) executionContext.getVariable("string_typeOfFishingLicense"); Timestamp fromStamp = (Timestamp) executionContext.getVariable("date_startOfFishing"); IWTimestamp from = new IWTimestamp(fromStamp); IWTimestamp to = new IWTimestamp(from); to.setMonth(8); to.setDay(31); if (to.isEarlierThan(from)) { to.addYears(1); } String areaID = null; Map<BigDecimal, VeidileyfagerdTypeUser> areas = getWSClient() .getAlmennAreas(FishingLicenseType.valueOf(subType)); if (areas != null && !areas.isEmpty()) { VeidileyfagerdTypeUser item = areas.values().iterator().next(); areaID = item.getVlyfId().toString(); } if (areaID == null) { throw new GumboProcessException("Error creating fishing license"); } fishingLicenseKey = getWSClient().createFishingLicense(shipID, areaID, from, to, theCase.getPrimaryKey().toString()); theCase.setMetaData(GumboConstants.DOF_FISHING_LICENSE_METADATA_KEY, fishingLicenseKey.toString()); if (fishingLicenseKey.intValue() == -1) { throw new GumboProcessException("Error creating fishing license"); } } boolean send = IWMainApplication.getDefaultIWApplicationContext().getApplicationSettings() .getBoolean("dof_send_claim", true); if (!send) { return; } // Create claim String claimKey = (subType == null) ? getFJSWSClient().createLicenseFeeClaim(ssn, shipID, getGumboDAO().getProcessPaymentCode(processDefinitionName)) : getFJSWSClient().createLicenseFeeClaim(ssn, shipID, getGumboDAO().getProcessPaymentCode(processDefinitionName, subType)); // System.out.println("claimKey = " + claimKey); if (claimKey != null) { theCase.setMetaData(GumboConstants.FJS_CLAIM_NUMBER_METADATA_KEY, claimKey); } else { getWSClient().cancelFishingLicense(fishingLicenseKey); // throw some exception!!!! throw new GumboProcessException("Error registering the claim"); } }
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());/*from w w w . ja v a2s . c o m*/ 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.jasig.ssp.service.impl.EvaluatedSuccessIndicatorServiceImpl.java
private Pair<Object, String> findCreditCompletionMetric(@Nonnull SuccessIndicator successIndicator, @Nonnull Person person) {/*from w w w . j a va2s . com*/ final ExternalStudentTranscript transcript = findTranscriptFor(person); BigDecimal completionRatio = null; if (transcript != null) { completionRatio = transcript.getCreditCompletionRate(); } return new Pair<Object, String>(completionRatio, (completionRatio == null ? null : completionRatio.toString() + "%")); }
From source file:org.finra.dm.dao.impl.EmrDaoImpl.java
/** * Create the instance group configuration. * * @param roleType role type for the instance group (MASTER/CORE/TASK). * @param instanceType EC2 instance type for the instance group. * @param instanceCount number of instances for the instance group. * @param bidPrice bid price in case of SPOT instance request. * * @return the instance group config object. */// w w w. j av a2 s. c om private InstanceGroupConfig getInstanceGroupConfig(InstanceRoleType roleType, String instanceType, Integer instanceCount, BigDecimal bidPrice) { InstanceGroupConfig instanceGroup = new InstanceGroupConfig(roleType, instanceType, instanceCount); // Consider spot price, if specified if (bidPrice != null) { instanceGroup.setMarket(MarketType.SPOT); instanceGroup.setBidPrice(bidPrice.toString()); } return instanceGroup; }
From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImpl.java
/** * Creates a set of BigDecimals with range values, and chose correct values from the attData for this list. * @param numberAttData contains informations about the new values. * @param userLog the processing log for saving import messages * @return Set with all correct values as bigDecimal *//*from w ww . ja v a2 s. com*/ private Set<BigDecimal> getBigDecimalRanges(NumberAttData numberAttData, ProcessingLog userLog) { Set<BigDecimal> userRangesToAdd = Sets.newHashSet(); String celLRef = numberAttData.getUserRanges().getCellRef(); for (String rangeStr : toList(numberAttData.getUserRanges())) { BigDecimal value; try { value = new BigDecimal(rangeStr).setScale(2); } catch (NumberFormatException e) { userLog.error("[{0}] Invalid format for range value: {1}", celLRef, rangeStr); LOGGER.debug(e); continue; } if (userRangesToAdd.contains(value)) { userLog.warn("[{0}] Range value is twice: {1}", celLRef, value.toString()); } if (userRangesToAdd.size() >= Constants.MAX_RANGELIST_SIZE) { userLog.error("[{0}] Cant save more than {1} value ranges. Skipping range with value \"{2}\".", celLRef, Integer.valueOf(Constants.MAX_RANGELIST_SIZE), value.toString()); continue; } userRangesToAdd.add(value); } return userRangesToAdd; }