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 NumberFormat getCurrencyInstance(Locale inLocale) 

Source Link

Document

Returns a currency format for the specified locale.

Usage

From source file:codingpractice.renard314.com.products.ProductGridAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
    final ProductViewHolder holder;
    if (convertView == null) {
        convertView = mLayoutInflater.inflate(R.layout.product_grid_item, viewGroup, false);
        holder = new ProductViewHolder(convertView);
        convertView.setTag(holder);//from   ww  w. ja va 2  s. c  om
    } else {
        holder = (ProductViewHolder) convertView.getTag();
    }
    final Product product = mProducts.get(position);
    startLoadImage(convertView, holder, product);
    //US $ or Singapore $ looks the same to me but a proper shopping app handles currencies differently.
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.US);
    holder.priceView.setText(format.format(product.pricing.price));
    holder.titleView.setText(product.title);
    holder.mMeasureView.setText(product.measure.wt_or_vol);

    return convertView;
}

From source file:com.expressui.core.view.field.format.DefaultFormats.java

/**
 * Gets number format for currency.//from w  w w.jav a  2  s . com
 *
 * @param locale                locale to apply to format, useful for displaying currencies other than
 *                              the standard currency of the user's locale.
 * @param maximumFractionDigits maximum number of fraction digits
 * @return currency property formatter
 */
public PropertyFormatter getCurrencyFormat(Locale locale, int maximumFractionDigits) {
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(locale);
    numberFormat.setMaximumFractionDigits(maximumFractionDigits);
    return new JDKBridgePropertyFormatter(numberFormat);
}

From source file:com.codebutler.farebot.transit.orca.OrcaTransitData.java

@Override
public String getBalanceString() {
    return NumberFormat.getCurrencyInstance(Locale.US).format(mBalance / 100);
}

From source file:codingpractice.renard314.com.products.ui.ProductDetailFragment.java

@Nullable
@Override//  ww w  . j  a va  2  s.co m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_product_details, container, false);
    ButterKnife.inject(this, view);
    MainActivity activity = (MainActivity) getActivity();
    activity.setSupportActionBar(mToolbar);
    activity.getSupportActionBar().setHomeButtonEnabled(true);
    activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ViewCompat.setElevation(mToolbar, 4f);

    final Product product = getArguments().getParcelable(ARG_PRODUCT);

    mFlexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    mFlexibleSpaceShowFabOffset = getResources().getDimensionPixelSize(R.dimen.flexible_space_show_fab_offset);
    mActionBarSize = getActionBarSize();
    mToolbar.setTitle(null);
    mScrollView.setScrollViewCallbacks(this);
    mTitleView.setText(product.title);
    mMeasureView.setText(product.measure.wt_or_vol);
    mDescriptionTextView.setText(product.desc);
    //product information should really contain currency information and amount should not be in float either
    //this is a demo so displaying as $ is fine.
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.US);
    mPriceView.setText(format.format(product.pricing.price));

    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getActivity(), "Item added to cart.", Toast.LENGTH_SHORT).show();
        }
    });
    mBackGroundColor = getResources().getColor(R.color.colorAccent);
    //workaround for library bug
    mFab.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    ViewHelper.setScaleX(mFab, 0);
    ViewHelper.setScaleY(mFab, 0);

    ScrollUtils.addOnGlobalLayoutListener(mScrollView, new Runnable() {
        @Override
        public void run() {
            //mScrollView.scrollTo(0, mFlexibleSpaceImageHeight);
            //onScrollChanged(0, false, false);
            mScrollView.scrollTo(0, 1);
            mScrollView.scrollTo(0, 0);
        }
    });

    startLoadingImage(mImageView, product.img.name, true);
    String secondaryImage = findSecondaryImageThatIsDifferentToMainImage(product);
    if (secondaryImage != null) {
        startLoadingImage(mSecondImageView, secondaryImage, false);
    } else {
        mSecondImageView.setVisibility(View.GONE);
    }
    return view;
}

From source file:org.apache.click.util.Format.java

/**
 * Return a currency formatted String value for the given number, using
 * the default Locale.//  w w w  .j  a v a  2s. co  m
 * <p/>
 * If the number is null this method will return the
 * {@link #getEmptyString()} value.
 *
 * @param number the number to format
 * @return a currency formatted number string
 */
public String currency(Number number) {
    if (number != null) {
        NumberFormat format = NumberFormat.getCurrencyInstance(getLocale());

        return format.format(number.doubleValue());

    } else {
        return getEmptyString();
    }
}

From source file:org.mentawai.util.StringUtils.java

/**
* Convert Money value as String to a Number
* @param value/*from   w ww  . ja v  a2  s . c o  m*/
* @param loc (Optional) Default is LocaleManager.DEFAULT_LOCALE
*/
public static Number parseCurrencyNumber(String value, Locale loc) throws ParseException {
    if (loc == null)
        loc = LocaleManager.DEFAULT_LOCALE;
    String symbol = DecimalFormatSymbols.getInstance(loc).getCurrencySymbol();
    if ("R$".equals(symbol))
        symbol += " "; // Caso seja a moeda Real.
    Number number = NumberFormat.getCurrencyInstance(loc).parse(symbol + value);
    return number;
}

From source file:org.moqui.impl.context.L10nFacadeImpl.java

@Override
public String formatCurrency(Object amount, String uomId, Integer fractionDigits, Locale locale) {
    if (amount == null)
        return "";
    if (amount instanceof CharSequence) {
        if (((CharSequence) amount).length() == 0) {
            return "";
        } else {//from  ww w . j a  va2s  . c  o m
            amount = parseNumber((String) amount, null);
        }
    }

    if (locale == null)
        locale = getLocale();
    NumberFormat nf = NumberFormat.getCurrencyInstance(locale);
    Currency currency = uomId != null && uomId.length() > 0 ? Currency.getInstance(uomId) : null;
    if (currency != null)
        nf.setCurrency(currency);
    if (fractionDigits == null)
        fractionDigits = currency != null ? currency.getDefaultFractionDigits() : 2;
    nf.setMaximumFractionDigits(fractionDigits);
    nf.setMinimumFractionDigits(fractionDigits);
    return nf.format(amount);
}

From source file:Money.java

public String displayAsDollars() {
    NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);

    if (delegate.signum() < 0) {
        this.delegate = delegate.negate();
        //String dis = "-$" + this.toString();
        this.delegate = this.delegate.negate();
        //return dis;
        return nf.format(this.delegate);
    } else {// w  ww  . jav a2  s .  c o  m
        return nf.format(this.delegate);
        //return "$" + toString();
    }
}

From source file:com.codebutler.farebot.transit.suica.SuicaTrip.java

@Override
public String getFareString() {
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN);
    format.setMaximumFractionDigits(0);/*from www  . j  a v a 2 s . c o  m*/
    if (mFare < 0) {
        return "+" + format.format(-mFare);
    } else {
        return format.format(mFare);
    }
}

From source file:com.codebutler.farebot.transit.suica.SuicaTrip.java

@Override
public String getBalanceString() {
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.JAPAN);
    format.setMaximumFractionDigits(0);/* w ww  .j a  v a  2 s .c  o m*/
    return format.format(mBalance);
}