Example usage for java.text NumberFormat getCurrencyInstance

List of usage examples for java.text NumberFormat getCurrencyInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getCurrencyInstance.

Prototype

public static final NumberFormat getCurrencyInstance() 

Source Link

Document

Returns a currency format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.dabay6.android.apps.carlog.ui.statistics.fragments.FillUpsFragment.java

/**
 * {@inheritDoc}//  w  w w.j a  v a  2  s. c om
 */
@Override
public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) {
    final DetailsAdapter adapter;
    final DetailsItemList items = new DetailsItemList();

    if (DataUtils.hasData(cursor)) {
        final String[] columnNames = cursor.getColumnNames();

        for (final String columnName : columnNames) {
            if (!columnName.equalsIgnoreCase(Columns.VEHICLE_ID.getName())) {
                final DetailsItem item;
                final int index = cursor.getColumnIndex(columnName);
                final String text;
                final float value = cursor.getFloat(index);

                if (columnName.equalsIgnoreCase(Columns.TOTAL_FILL_UPS.getName())) {
                    text = StringUtils.format("%.0f", value);
                } else if (columnName.equalsIgnoreCase(Columns.MAX_FUEL_AMOUNT.getName())
                        || columnName.equalsIgnoreCase(Columns.MIN_FUEL_AMOUNT.getName())) {
                    text = StringUtils.format(getString(R.string.gallons), value);
                } else {
                    final NumberFormat currency = NumberFormat.getCurrencyInstance();

                    text = currency.format(cursor.getFloat(index));
                }

                item = new DetailsItem(StringUtils.splitIntoWords(columnName), text);

                items.add(item);
            }
        }
    }

    adapter = new DetailsAdapter(getActivity(), items, layout.list_item_statistics);

    setListAdapter(adapter);

    if (isResumed()) {
        setListShown(true);
    } else {
        setListShownNoAnimation(true);
    }
}

From source file:org.hoteia.qalingo.core.domain.CurrencyReferential.java

public NumberFormat getStandardCurrencyformat() {
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    if (StringUtils.isNotEmpty(getFormatLocale())) {
        formatter = NumberFormat.getCurrencyInstance(getLocale());
    }/*  w ww  .j  a  v a  2  s .  c  o m*/
    Currency currency = Currency.getInstance(getCode());
    formatter.setCurrency(currency);
    return formatter;
}

From source file:com.dabay6.android.apps.carlog.ui.fuel.fragments.FuelHistoryDetailFragment.java

/**
 * {@inheritDoc}/*ww w  . ja v  a  2 s .  c om*/
 */
@SuppressWarnings("unchecked")
@Override
protected void createListItems(final Cursor cursor) {
    if (DataUtils.hasData(cursor)) {
        final Bundle bundle = getArguments();
        final FuelHistoryDTO history = FuelHistoryDTO.newInstance(cursor);
        final NumberFormat currency = NumberFormat.getCurrencyInstance();
        final String purchaseDate;

        purchaseDate = DateUtils.getUserLocaleFormattedDate(getActivity(), history.getPurchaseDate(),
                DateFormats.Medium);

        setTitle(string.fuel_history_details);
        setSubtitle(history.getName());

        if (isDualPane()) {
            adapter.clear();
        }

        adapter.add(createDetailItem(Columns.PURCHASE_DATE, purchaseDate));
        adapter.add(createDetailItem(Columns.ODOMETER_READING,
                getString(R.string.fuel_history_miles, history.getOdometerReading())));

        if (bundle != null && bundle.containsKey(PARAMS_MPG)) {
            final float mpg = bundle.getFloat(PARAMS_MPG);

            adapter.add(getString(string.fuel_history_mpg),
                    String.format(getString(string.miles_per_gallon), mpg));
        }

        currency.setMaximumFractionDigits(2);
        adapter.add(createDetailItem(Columns.TOTAL_COST, currency.format(history.getTotalCost())));

        adapter.add(createDetailItem(Columns.FUEL_AMOUNT, history.getFuelAmount().toString()));

        currency.setMaximumFractionDigits(3);
        adapter.add(createDetailItem(Columns.COST_PER_UNIT, currency.format(history.getCostPerUnit())));

        getActivity().supportInvalidateOptionsMenu();
    }
}

From source file:org.jbpm.bpel.tutorial.shipping.ShippingPT_Impl.java

public void init(Object context) throws ServiceException {
    // initialize jms administered objects
    try {// ww w  .j av a2s. c  o m
        initJmsObjects();
    } catch (Exception e) {
        throw new ServiceException("Could not initialize jms objects", e);
    }

    // retrieve servlet context
    ServletEndpointContext endpointContext = (ServletEndpointContext) context;
    ServletContext servletContext = endpointContext.getServletContext();

    // initialize shipping price parameter
    String shippingPriceString = servletContext.getInitParameter(SHIPPING_PRICE_PARAM);
    if (shippingPriceString == null) {
        throw new ServiceException("Required parameter not found: " + SHIPPING_PRICE_PARAM);
    }

    NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
    try {
        shippingPrice = currencyFormat.parse(shippingPriceString).floatValue();
        log.debug("Set parameter: " + SHIPPING_PRICE_PARAM + ", value=" + shippingPrice);
    } catch (ParseException e) {
        throw new ServiceException("Invalid parameter: " + SHIPPING_PRICE_PARAM, e);
    }
}

From source file:org.gastro.server.internal.web.GastroServlet.java

public static String html(double value) {
    return html(NumberFormat.getCurrencyInstance().format(value));
}

From source file:com.dabay6.android.apps.carlog.adapters.FuelHistoryCursorAdapter.java

/**
 * @param context/*from w ww  .  ja v  a  2s  . c o m*/
 * @param view
 * @param cursor
 */
@Override
protected void populateData(final Context context, final View view, final Cursor cursor) {
    final NumberFormat currency = NumberFormat.getCurrencyInstance();
    final ViewsFinder finder = new ViewsFinder(view);
    final TextView dateTime = finder.find(R.id.datetime);
    final TextView odometer = finder.find(R.id.odometer);
    final TextView mpg = finder.find(R.id.mpg);
    final TextView price = finder.find(R.id.price);
    final TextView total = finder.find(R.id.total);
    final TextView volume = finder.find(R.id.volume);
    final FuelHistoryDTO history = FuelHistoryDTO.newInstance(cursor);
    final Pair<Float, String> calculated = calculateMilesPerGallon(context, history, cursor);

    milesPerGallon.put(history.getHistoryId(), calculated.first);

    dateTime.setText(
            DateUtils.getUserLocaleFormattedDate(context, history.getPurchaseDate(), DateFormats.Medium));
    mpg.setText(calculated.second);
    odometer.setText(
            StringUtils.format(context.getString(R.string.fuel_history_miles), history.getOdometerReading()));
    volume.setText(StringUtils.format(context.getString(R.string.gallons), history.getFuelAmount()));

    currency.setMaximumFractionDigits(3);
    price.setText(
            context.getString(R.string.fuel_history_cost_per_unit, currency.format(history.getCostPerUnit())));

    currency.setMaximumFractionDigits(2);
    total.setText(currency.format(history.getTotalCost()));
}

From source file:org.ojbc.bundles.adapters.staticmock.samplegen.WarrantSampleGenerator.java

@Override
protected List<Document> generateSample(Collection<PersonElementWrapper> people, DateTime baseDate,
        String stateParam) throws Exception {

    List<Document> personDocuments = new ArrayList<Document>();

    LOG.info("Processing " + people.size() + " records");

    for (PersonElementWrapper person : people) {

        Document ret = documentBuilder.newDocument();
        personDocuments.add(ret);/* w w  w .jav  a 2 s  .c  o  m*/

        Element e = null;

        e = ret.createElementNS(OjbcNamespaceContext.NS_WARRANT, "Warrants");
        ret.appendChild(e);
        e.setPrefix(OjbcNamespaceContext.NS_PREFIX_WARRANT);

        e = appendElement(e, OjbcNamespaceContext.NS_WARRANT_EXT, "eBWResults");

        addPersonElement(e, person, baseDate);
        addLocationElement(e, person);

        e = appendElement(e, OjbcNamespaceContext.NS_WARRANT_EXT, "eBWResult");
        Element ebw = e;

        e = appendElement(e, OjbcNamespaceContext.NS_JXDM_41, "Case");
        Element caseElement = e;
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "ActivityStatus");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "StatusDescriptionText");
        e.setTextContent("Open");

        e = appendElement(caseElement, OjbcNamespaceContext.NS_NC, "CaseDocketID");
        e.setTextContent(generateRandomID("C", 2) + "-" + generateRandomID("", 4));

        e = appendElement(ebw, OjbcNamespaceContext.NS_WARRANT_EXT, "eBWWarrantStatus");
        e.setTextContent("Active");

        e = appendElement(ebw, OjbcNamespaceContext.NS_JXDM_41, "Bail");
        Element bail = e;
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "ActivityStatus");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "StatusDescriptionText");
        e.setTextContent("Posted");
        e = appendElement(bail, OjbcNamespaceContext.NS_JXDM_41, "BailSetAmount");
        e.setTextContent(
                NumberFormat.getCurrencyInstance().format(generateUniformDouble(1000.00)).replace("$", ""));

        e = appendElement(ebw, OjbcNamespaceContext.NS_JXDM_41, "Warrant");
        Element warrant = e;

        e = appendElement(warrant, OjbcNamespaceContext.NS_NC, "ActivityIdentification");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "IdentificationID");
        e.setTextContent(generateRandomID("WRT", 10));
        e = appendElement(warrant, OjbcNamespaceContext.NS_NC, "ActivityStatus");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "StatusDescriptionText");
        e.setTextContent("Active");
        e = appendElement(warrant, OjbcNamespaceContext.NS_JXDM_41, "CourtOrderDesignatedSubject");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "RoleOfPersonReference");
        XmlUtils.addAttribute(e, OjbcNamespaceContext.NS_STRUCTURES, "ref", person.personId);
        e = appendElement(warrant, OjbcNamespaceContext.NS_JXDM_41, "CourtOrderIssuingDate");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "Date");
        DateTime orderDate = generateNormalRandomDateBefore(baseDate, 30);
        DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd");
        e.setTextContent(fmt.print(orderDate));
        e = appendElement(warrant, OjbcNamespaceContext.NS_JXDM_41, "CourtOrderJurisdiction");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "JurisdictionText");
        e.setTextContent("District Court");
        e = appendElement(warrant, OjbcNamespaceContext.NS_JXDM_41, "CourtOrderStatus");
        e = appendElement(e, OjbcNamespaceContext.NS_NC, "StatusDescriptionText");
        e.setTextContent("Open");
        e = appendElement(warrant, OjbcNamespaceContext.NS_JXDM_41, "WarrantLevelText");
        e.setTextContent(generateRandomCodeFromList("Traffic", "Felony"));

        OJBC_NAMESPACE_CONTEXT.populateRootNamespaceDeclarations(ret.getDocumentElement());

    }
    return personDocuments;

}

From source file:com.trenako.entities.Money.java

@Override
public String toString() {
    if (this == EMPTY_VALUE) {
        return "-";
    }/*from   ww  w .  j  a v  a2 s  .  co m*/

    BigDecimal v = BigDecimal.valueOf(getValue()).divide(MONEY_VALUE_FACTOR);

    NumberFormat nf = NumberFormat.getCurrencyInstance();

    // the user may have selected a different currency than the default
    Currency currency = Currency.getInstance(getCurrency());
    nf.setCurrency(currency);
    nf.setMinimumFractionDigits(2);

    return nf.format(v);
}

From source file:org.openvpms.report.AbstractExpressionEvaluator.java

/**
 * Returns the formatted value of an expression.
 *
 * @param expression the expression/* ww  w  .j  a v a  2s . co m*/
 * @return the result of the expression
 */
@Override
public String getFormattedValue(String expression) {
    Object value = getValue(expression);
    if (value instanceof Date) {
        Date date = (Date) value;
        return DateFormat.getDateInstance(DateFormat.MEDIUM).format(date);
    } else if (value instanceof Money) {
        return NumberFormat.getCurrencyInstance().format(value);
    } else if (value instanceof BigDecimal) {
        DecimalFormat format = new DecimalFormat("#,##0.00;-#,##0.00");
        return format.format(value);
    } else if (value instanceof IMObject) {
        return getValue((IMObject) value);
    } else if (value instanceof IMObjectReference) {
        return getValue((IMObjectReference) value);
    } else if (value != null) {
        return value.toString();
    }
    return null;
}

From source file:com.dgsd.android.ShiftTracker.Fragment.HoursAndIncomeSummaryFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    PayAndDuration pad = PayAndDuration.from(cursor);

    TextView view = null;//from   w w w.  j  a v a 2  s. c  o m
    switch (loader.getId()) {
    case LOADER_ID_MONTH:
        view = mMonth;
        break;
    case LOADER_ID_3_MONTH:
        view = mThreeMonth;
        break;
    case LOADER_ID_6_MONTH:
        view = mSixMonth;
        break;
    case LOADER_ID_9_MONTH:
        view = mNineMonth;
        break;
    case LOADER_ID_YEAR:
        view = mThisYear;
        break;
    }

    if (view == null)
        return;

    String payText = NumberFormat.getCurrencyInstance().format(pad.pay);
    String hoursText = UIUtils.getDurationAsHours(pad.mins);

    view.setText(payText + "\n" + hoursText);
}