List of usage examples for java.text NumberFormat getCurrencyInstance
public static final NumberFormat getCurrencyInstance()
From source file:org.kuali.ext.mm.web.format.MMDecimalFormatter.java
/** * retrieves a currency formatter instance and sets ParseBigDecimal to true to fix [KULEDOCS-742] * /*ww w .ja v a2s.c o m*/ * @return CurrencyInstance */ static final NumberFormat getCurrencyInstanceUsingParseBigDecimal() { NumberFormat formatter = NumberFormat.getCurrencyInstance(); if (formatter instanceof DecimalFormat) { ((DecimalFormat) formatter).setParseBigDecimal(true); } return formatter; }
From source file:FormattedTextFieldDemo.java
private void setUpFormats() { amountFormat = NumberFormat.getNumberInstance(); percentFormat = NumberFormat.getNumberInstance(); percentFormat.setMinimumFractionDigits(3); paymentFormat = NumberFormat.getCurrencyInstance(); }
From source file:org.totschnig.myexpenses.util.Utils.java
private static void initNumberFormat() { String prefFormat = PrefKey.CUSTOM_DECIMAL_FORMAT.getString(""); if (!prefFormat.equals("")) { DecimalFormat nf = new DecimalFormat(); try {/*from www . j a v a 2 s .c o m*/ nf.applyLocalizedPattern(prefFormat); numberFormat = nf; } catch (IllegalArgumentException e) { //fallback to default currency instance numberFormat = NumberFormat.getCurrencyInstance(); } } else { numberFormat = NumberFormat.getCurrencyInstance(); } }
From source file:com.microsoft.azure.engagement.ProductDiscountActivity.java
/** * Formats a specific price/*from ww w . ja v a 2s . c o m*/ * * @param finalPrice The price to format * @return The price formatted */ private final String getPrice(double finalPrice) { final NumberFormat formatter = NumberFormat.getCurrencyInstance(); return formatter.format(finalPrice); }
From source file:FormatterFactoryDemo.java
private void setUpFormats() { amountDisplayFormat = NumberFormat.getCurrencyInstance(); amountDisplayFormat.setMinimumFractionDigits(0); amountEditFormat = NumberFormat.getNumberInstance(); percentDisplayFormat = NumberFormat.getPercentInstance(); percentDisplayFormat.setMinimumFractionDigits(2); percentEditFormat = NumberFormat.getNumberInstance(); percentEditFormat.setMinimumFractionDigits(2); paymentFormat = NumberFormat.getCurrencyInstance(); }
From source file:org.broadleafcommerce.core.offer.handler.OfferCustomPersistenceHandler.java
@Override public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException { DynamicResultSet resultSet = helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto); String customCriteria = ""; if (persistencePackage.getCustomCriteria().length > 0) { customCriteria = persistencePackage.getCustomCriteria()[0]; }// w w w . jav a 2s .c o m for (Entity entity : resultSet.getRecords()) { Property discountType = entity.findProperty("discountType"); Property discountValue = entity.findProperty("value"); String value = discountValue.getValue(); if (discountType.getValue().equals("PERCENT_OFF")) { value = value.indexOf(".") < 0 ? value : value.replaceAll("0*$", "").replaceAll("\\.$", ""); discountValue.setValue(value + "%"); } else if (discountType.getValue().equals("AMOUNT_OFF")) { NumberFormat nf = NumberFormat.getCurrencyInstance(); discountValue.setValue(nf.format(new BigDecimal(value))); } else if (discountType.getValue().equals("")) { discountValue.setValue(""); } Property timeRule = entity.findProperty("offerMatchRules---TIME"); entity.addProperty(buildAdvancedVisibilityOptionsProperty(timeRule)); Property offerItemQualifierRuleType = entity.findProperty(OFFER_ITEM_QUALIFIER_RULE_TYPE); entity.addProperty(buildQualifiersCanBeQualifiersProperty(offerItemQualifierRuleType)); entity.addProperty(buildQualifiersCanBeTargetsProperty(offerItemQualifierRuleType)); Property offerItemTargetRuleType = entity.findProperty(OFFER_ITEM_TARGET_RULE_TYPE); entity.addProperty(buildStackableProperty(offerItemTargetRuleType)); if (!"listGridView".equals(customCriteria)) { String setValue = discountValue.getValue(); setValue = setValue.replaceAll("\\%", "").replaceAll("\\$", ""); discountValue.setValue(setValue); } } return resultSet; }
From source file:org.kuali.rice.krad.labs.transaction.TransactionForm.java
public String getFormattedStartingBalance() { NumberFormat percentFormat = NumberFormat.getCurrencyInstance(); return percentFormat.format(this.getStartingBalance()); }
From source file:org.angnysa.yaba.swing.BudgetFrame.java
private void buildSimulationPanel() { simulationPanel = new JPanel(); SpringLayout springLayout = new SpringLayout(); simulationPanel.setLayout(springLayout); // chart data simulationDataset = new SimulationDataset(service); simulationDataset.setInitial(0D);// ww w .j av a2 s.c o m simulationDataset.setStart(new LocalDate()); simulationDataset.setEnd(new LocalDate().plus(Years.ONE)); simulationDataset.setPeriod(Period.months(1)); simulationDataset.updateDataset(); transactionModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { simulationDataset.updateDataset(); } }); reconciliationModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { simulationDataset.updateDataset(); } }); // initial amount label JLabel amountLbl = new JLabel(Messages.getString("simulation.field.initial-amount")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, amountLbl, 10, SpringLayout.WEST, simulationPanel); simulationPanel.add(amountLbl); // initial amount field amountFld = new JFormattedTextField( new DefaultFormatterFactory(new NumberFormatter(NumberFormat.getNumberInstance()), new NumberFormatter(NumberFormat.getCurrencyInstance()))); amountFld.setColumns(8); amountFld.setValue(simulationDataset.getInitial()); amountFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setInitial(((Number) amountFld.getValue()).doubleValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, amountLbl, 0, SpringLayout.VERTICAL_CENTER, amountFld); springLayout.putConstraint(SpringLayout.WEST, amountFld, 0, SpringLayout.EAST, amountLbl); springLayout.putConstraint(SpringLayout.NORTH, amountFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(amountFld); // start date label JLabel fromLbl = new JLabel(Messages.getString("simulation.field.start-date")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, fromLbl, 10, SpringLayout.EAST, amountFld); simulationPanel.add(fromLbl); // start date field fromFld = new JFormattedTextField(new JodaLocalDateFormat()); fromFld.setColumns(8); fromFld.setValue(simulationDataset.getStart()); fromFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setStart((LocalDate) fromFld.getValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, fromLbl, 0, SpringLayout.VERTICAL_CENTER, fromFld); springLayout.putConstraint(SpringLayout.WEST, fromFld, 0, SpringLayout.EAST, fromLbl); springLayout.putConstraint(SpringLayout.NORTH, fromFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(fromFld); // end date label JLabel toLbl = new JLabel(Messages.getString("simulation.field.end-date")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, toLbl, 10, SpringLayout.EAST, fromFld); simulationPanel.add(toLbl); // end date field toFld = new JFormattedTextField(new JodaLocalDateFormat()); toFld.setColumns(8); toFld.setValue(simulationDataset.getEnd()); toFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setEnd((LocalDate) toFld.getValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, toLbl, 0, SpringLayout.VERTICAL_CENTER, toFld); springLayout.putConstraint(SpringLayout.WEST, toFld, 0, SpringLayout.EAST, toLbl); springLayout.putConstraint(SpringLayout.NORTH, toFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(toFld); // period label JLabel periodLbl = new JLabel(Messages.getString("simulation.field.period")); //$NON-NLS-1$ springLayout.putConstraint(SpringLayout.WEST, periodLbl, 10, SpringLayout.EAST, toFld); simulationPanel.add(periodLbl); // period field periodFld = new JFormattedTextField(new JodaPeriodFormat()); periodFld.setColumns(5); periodFld.setValue(simulationDataset.getPeriod()); periodFld.addPropertyChangeListener("value", new PropertyChangeListener() { //$NON-NLS-1$ @Override public void propertyChange(PropertyChangeEvent e) { simulationDataset.setPeriod((ReadablePeriod) periodFld.getValue()); simulationDataset.updateDataset(); } }); springLayout.putConstraint(SpringLayout.VERTICAL_CENTER, periodLbl, 0, SpringLayout.VERTICAL_CENTER, periodFld); springLayout.putConstraint(SpringLayout.WEST, periodFld, 0, SpringLayout.EAST, periodLbl); springLayout.putConstraint(SpringLayout.NORTH, periodFld, 10, SpringLayout.NORTH, simulationPanel); simulationPanel.add(periodFld); // chart panel JFreeChart chart = ChartFactory.createLineChart("", Messages.getString("simulation.chart.date-axis-label"), //$NON-NLS-1$//$NON-NLS-2$ Messages.getString("simulation.chart.amount-axis-label"), simulationDataset, //$NON-NLS-1$ PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45); LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesFilled(true); renderer.setBaseShapesVisible(true); renderer.setBaseToolTipGenerator(new SimulationTooltipGenerator(service)); ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setDismissDelay(3600000); chartPanel.setInitialDelay(0); springLayout.putConstraint(SpringLayout.NORTH, chartPanel, 15, SpringLayout.SOUTH, periodFld); springLayout.putConstraint(SpringLayout.WEST, chartPanel, 10, SpringLayout.WEST, simulationPanel); springLayout.putConstraint(SpringLayout.SOUTH, chartPanel, -10, SpringLayout.SOUTH, simulationPanel); springLayout.putConstraint(SpringLayout.EAST, chartPanel, -10, SpringLayout.EAST, simulationPanel); simulationPanel.add(chartPanel); }
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
private void processDebit(ViewHolder holder, int position) { mCursor.moveToPosition(position);//w w w . j a va2 s .co m // Set the account String fromAccount = mCursor.getString(TransactionsFragment.COLUMN_FROM_ACCOUNT_TITLE); holder.mAccount.setText(fromAccount); // Set the amount double fromAmount = NumberUtils .roundToTwoPlaces(0 - mCursor.getLong(TransactionsFragment.COLUMN_FROM_AMOUNT) / 100.0); NumberFormat format = NumberFormat.getCurrencyInstance(); String fromCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_FROM_CURRENCY); Currency fromCurrency = Currency.getInstance(fromCurrencyCode); format.setCurrency(fromCurrency); format.setMaximumFractionDigits(fromCurrency.getDefaultFractionDigits()); holder.mAmount.setText(format.format(fromAmount)); holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorRed700)); double fromBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_FROM_BALANCE) / 100.0); holder.mRunningBalance.setText(format.format(fromBalance)); // Set the transaction type icon holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_call_made_black_24dp, R.color.colorRed700)); }
From source file:ro.expectations.expenses.ui.transactions.TransactionsAdapter.java
private void processCredit(ViewHolder holder, int position) { mCursor.moveToPosition(position);//from w w w . j a v a2s . com // Set the account String toAccount = mCursor.getString(TransactionsFragment.COLUMN_TO_ACCOUNT_TITLE); holder.mAccount.setText(toAccount); // Set the amount double toAmount = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_AMOUNT) / 100.0); NumberFormat format = NumberFormat.getCurrencyInstance(); String toCurrencyCode = mCursor.getString(TransactionsFragment.COLUMN_TO_CURRENCY); Currency toCurrency = Currency.getInstance(toCurrencyCode); format.setCurrency(toCurrency); format.setMaximumFractionDigits(toCurrency.getDefaultFractionDigits()); holder.mAmount.setText(format.format(toAmount)); holder.mAmount.setTextColor(ContextCompat.getColor(mContext, R.color.colorGreen700)); double toBalance = NumberUtils .roundToTwoPlaces(mCursor.getLong(TransactionsFragment.COLUMN_TO_BALANCE) / 100.0); holder.mRunningBalance.setText(format.format(toBalance)); // Set the transaction type icon holder.mTypeIcon.setImageDrawable( DrawableHelper.tint(mContext, R.drawable.ic_call_received_black_24dp, R.color.colorGreen700)); }