List of usage examples for java.math BigDecimal toString
@Override
public String toString()
From source file:com.salesmanager.core.util.CurrencyUtil.java
public static String displayEditablePriceWithCurrency(String textname, int textsize, boolean displaycurrency, BigDecimal amount, String currencycode, String appender) { if (currencycode == null) { currencycode = getDefaultCurrency(); }/*from w w w . j a v a 2 s .c o m*/ StringBuffer formatedfieldbuffer = new StringBuffer(); CurrencyModule module = (CurrencyModule) currencyMap.get(currencycode); if (module == null) { log.error("There is no CurrencyModule defined for currency " + currencycode + " in module/impl/application/currencies"); return amount.toString(); } String returnamount = ""; try { returnamount = module.getFormatedAmount(amount); } catch (Exception e) { log.error("Cannot format amount " + amount.toString() + " for currency " + currencycode); returnamount = amount.toString(); } String display = module.getCurrencySymbol(); return new StringBuffer().append(display).append(" ").append("<input type=\"text\" name=\"") .append(textname).append("\"").append(" id=\"").append(textname).append("\"").append(" value=\"") .append(returnamount).append("\"").append(" size=\"").append(textsize).append("\"") .append(appender != null ? " " + appender : "").append(">").toString(); }
From source file:com.salesmanager.core.util.CurrencyUtil.java
private static String displayFormatedAmount(BigDecimal amount, String currencycode) { try {// w w w . j a v a2 s . c o m if (amount == null) { return ""; } if (currencycode == null) { currencycode = getDefaultCurrency(); } CurrencyModule module = (CurrencyModule) currencyMap.get(currencycode); if (module == null) { log.error("There is no CurrencyModule defined for currency " + currencycode + " in module/impl/application/currencies"); return amount.toString(); } return module.getFormatedAmount(amount); } catch (Exception e) { log.error("Cannot format amount " + amount.toString() + " for currency " + currencycode); return amount.toString(); } }
From source file:com.salesmanager.core.util.CurrencyUtil.java
/** * For displaying weight, length, height and width * //from w w w. ja va2s .c o m * @param measure * @param currncycode * @return */ public static String displayMeasure(BigDecimal measure, String currencycode) { try { if (measure == null) { return ""; } if (currencycode == null) { currencycode = getDefaultCurrency(); } CurrencyModule module = (CurrencyModule) currencyMap.get(currencycode); if (module == null) { log.error("There is no CurrencyModule defined for currency " + currencycode + " in module/impl/application/currencies"); return measure.toString(); } return module.getMeasure(measure, currencycode); } catch (Exception e) { log.error("Cannot format measure " + measure.toString() + " for currency " + currencycode); return measure.toString(); } }
From source file:org.dbflute.solr.cbean.SolrQueryBuilder.java
/** * //from ww w. java2 s .c om * @param solrFieldName * @param from * @param to * @return */ public static String queryBuilderForRangeSearch(String solrFieldName, BigDecimal from, BigDecimal to) { String toStr = null; String fromStr = null; if (from == null) { fromStr = "*"; } else { fromStr = from.toString(); } if (to == null) { toStr = "*"; } else { toStr = to.toString(); } return queryBuilderForRangeSearch(solrFieldName, fromStr, toStr); }
From source file:nl.strohalm.cyclos.services.stats.tests.TestDatabaseForStats.java
private static void doInTransaction() throws Exception { final CalendarConverter calendarConverter = new CalendarConverter("yyyy/MM/dd"); final AccessService accessService = bean("accessService"); // final AccountService accountService = bean("accountService"); // final AccountTypeService accountTypeService = bean("accountTypeService"); final ElementService elementService = bean("elementService"); final GroupService groupService = bean("groupService"); final CustomFieldService customFieldService = bean("customFieldService"); final PaymentService paymentService = bean("paymentService"); final TransferTypeService transferTypeService = bean("transferTypeService"); final Session session = getSession(); final TransferType tradeTransferType = transferTypeService.load(13L); class TestMember { private Member member; TestMember(final MemberGroup memberGroup, final String name, final String creationDate) { member = new Member(); member.setGroup(memberGroup); member.setName(name);/*from w ww . ja v a2 s . co m*/ member.setEmail(name + "@members.com"); member.setUser(new MemberUser()); member.getUser().setUsername(name); member = (Member) elementService.registerMemberByAdmin(member, false); // creation date = current date member.setCreationDate(calendarConverter.valueOf(creationDate)); // set new creation date groupChanges.add(new GroupChange(member.getId(), member.getGroup().getId(), creationDate)); } void earnFrom(final TestMember payingMember, final BigDecimal amount, final String date) { final TransferDTO transferDto = new TransferDTO(); transferDto.setTransferType(tradeTransferType); transferDto.setContext(TransactionContext.PAYMENT); transferDto.setFromOwner(payingMember.member); transferDto.setToOwner(member); transferDto.setDate(calendarConverter.valueOf(date)); transferDto.setAmount(amount); transferDto.setDescription("from " + payingMember.member.getName() + " to " + member.getName() + "; " + amount.toString() + "; " + date); paymentService.insertWithoutNotification(transferDto); } void groupChange(final long newGroupId, final String date) { if (newGroupId > 0) { final MemberGroup newGroup = (MemberGroup) groupService.load(newGroupId); groupChanges.add(new GroupChange(member.getId(), member.getGroup().getId(), newGroupId, date)); elementService.changeMemberGroup(member, newGroup, "to group #" + newGroupId); // final GroupRemark gr = (GroupRemark) session.createCriteria(GroupRemark.class).add(Expression.eq("subject", // member)).uniqueResult(); final Calendar justNow = new GregorianCalendar(); justNow.add(Calendar.MINUTE, -5); final GroupRemark gr = (GroupRemark) session.createCriteria(GroupRemark.class) .add(Restrictions.eq("subject", member)).add(Restrictions.ge("date", justNow)) .addOrder(Order.asc("id")).setMaxResults(1).uniqueResult(); gr.setDate(calendarConverter.valueOf(date)); session.flush(); } } void login(final String[] loginList) { if (loginList != null) { for (final String login : loginList) { final LoginHistoryLog log = new LoginHistoryLog(); log.setUser(member.getUser()); log.setRemoteAddress("127.0.0.1"); log.setDate(calendarConverter.valueOf(login)); session.save(log); } } } } // Login as administrator to get service permissions final User admin = elementService.loadUser("admin"); accessService.login(admin, "1234", Channel.WEB, "localhost", "session1"); // Make all fields not required for (final CustomField field : customFieldService.listByNature(CustomField.Nature.MEMBER)) { field.getValidation().setRequired(false); customFieldService.save(field); } // Get group instances final MemberGroup fullMembersGroup = getMemberGroupFromId(5L, groupService); final MemberGroup fullBrokersGroup = getMemberGroupFromId(10L, groupService); // Set the initial credit final TransferType initialCredit = (TransferType) session.load(TransferType.class, 23L); final MemberGroupAccountSettings memberAccountSettings = fullMembersGroup.getAccountSettings().iterator() .next(); memberAccountSettings.setInitialCredit(new BigDecimal(1000)); memberAccountSettings.setInitialCreditTransferType(initialCredit); groupService.updateAccountSettings(memberAccountSettings, false); // Set the initial credit final MemberGroupAccountSettings brokerAccountSettings = fullBrokersGroup.getAccountSettings().iterator() .next(); brokerAccountSettings.setInitialCredit(new BigDecimal(1000)); brokerAccountSettings.setInitialCreditTransferType(initialCredit); groupService.updateAccountSettings(brokerAccountSettings, false); int transactionCounter = 0; // Create Test members final TestMember broker = new TestMember(fullBrokersGroup, "broker", brokerCreationDate); final TestMember member1 = new TestMember(getMemberGroupFromId(mem1StartGroup, groupService), "member1", member1CreationDate); final TestMember member2 = (member2CreationDate != null) ? new TestMember(getMemberGroupFromId(mem2StartGroup, groupService), "member2", member2CreationDate) : null; final TestMember member3 = (member3CreationDate != null) ? new TestMember(getMemberGroupFromId(mem3StartGroup, groupService), "member3", member3CreationDate) : null; final TestMember member4 = (member4CreationDate != null) ? new TestMember(getMemberGroupFromId(mem4StartGroup, groupService), "member4", member4CreationDate) : null; session.flush(); // apply group changes for (int i = 0; i < member1NewGroups.length; i++) { member1.groupChange(member1NewGroups[i], member1GroupChanges[i]); } // build login history member1.login(member1LoginList); // apply transactions for (final String element : member1EarnDates) { member1.earnFrom(broker, new BigDecimal(AMOUNTS[transactionCounter++]), element); } // repeat these blocks for other members // member 2: if (member2 != null) { for (int i = 0; i < member2NewGroups.length; i++) { member2.groupChange(member2NewGroups[i], member2GroupChanges[i]); } member2.login(member2LoginList); for (final String earnDate : member2EarnDates) { member2.earnFrom(broker, new BigDecimal(AMOUNTS[transactionCounter++]), earnDate); } } // member 3: if (member3 != null) { for (int i = 0; i < member3NewGroups.length; i++) { member3.groupChange(member3NewGroups[i], member3GroupChanges[i]); } member3.login(member3LoginList); for (final String earnDate : member3EarnDates) { member3.earnFrom(broker, new BigDecimal(AMOUNTS[transactionCounter++]), earnDate); } } // member 4: if (member4 != null) { for (int i = 0; i < member4NewGroups.length; i++) { member4.groupChange(member4NewGroups[i], member4GroupChanges[i]); } member4.login(member4LoginList); for (final String earnDate : member4EarnDates) { member4.earnFrom(broker, new BigDecimal(AMOUNTS[transactionCounter++]), earnDate); } } }
From source file:at.illecker.hama.hybrid.examples.summation.SummationBSP.java
static BigDecimal writeSummationInputFile(FileSystem fs, Path dir, int fileCount) throws IOException { BigDecimal sum = new BigDecimal(0); Random rand = new Random(); double rangeMin = 0; double rangeMax = 100; for (int i = 0; i < fileCount; i++) { DataOutputStream out = fs.create(new Path(dir, "part" + i)); // loop between 50 and 149 times for (int j = 0; j < rand.nextInt(100) + 50; j++) { // generate key value pair inputs double randomValue = rangeMin + (rangeMax - rangeMin) * rand.nextDouble(); String truncatedValue = new BigDecimal(randomValue) .setScale(DOUBLE_PRECISION, BigDecimal.ROUND_DOWN).toString(); String line = "key" + (j + 1) + "\t" + truncatedValue + "\n"; out.writeBytes(line);/*from w ww .j av a 2 s .com*/ sum = sum.add(new BigDecimal(truncatedValue)); LOG.debug("input[" + j + "]: '" + line + "' sum: " + sum.toString()); } out.close(); } return sum; }
From source file:org.onehippo.repository.mock.MockValueFactory.java
@Override public Value createValue(final BigDecimal value) { return new MockValue(PropertyType.DECIMAL, value.toString()); }
From source file:com.oflaherty.webservice.builders.request.RequestBuilder.java
private String convertBigDecimalToString(BigDecimal value) { if (value == null) { value = new BigDecimal("10"); }/*from w w w .ja va 2 s.co m*/ return value.toString(); }
From source file:org.kalypso.model.wspm.pdb.internal.waterlevel2d.Waterlevel2dWorker.java
public IStatus execute(final IProgressMonitor monitor) { /* hash by station */ final Map<BigDecimal, Collection<WaterlevelFixation>> waterlevelsByStation = hashWaterlevelsByStation(); monitor.beginTask(Messages.getString("Waterlevel2dWorker_0"), m_sections.length); //$NON-NLS-1$ for (final ISectionProvider sectionProvider : m_sections) { final BigDecimal station = sectionProvider.getStation(); monitor.subTask(station.toString()); final Collection<WaterlevelFixation> waterlevels = waterlevelsByStation.get(station); if (!CollectionUtils.isEmpty(waterlevels)) { final IStatus status = createWaterlevel(sectionProvider, waterlevels); m_log.add(status);/*from w ww. j a va 2s.com*/ } ProgressUtilities.worked(monitor, 1); } monitor.done(); return m_log.asMultiStatusOrOK(Messages.getString("Waterlevel2dWorker_1")); //$NON-NLS-1$ }
From source file:de.kopis.glacier.util.VaultInventoryPrinter.java
private String round(final String unrounded, final int precision, final int roundingMode) { final BigDecimal bd = new BigDecimal(unrounded); final BigDecimal rounded = bd.setScale(precision, roundingMode); return rounded.toString(); }