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:org.jbpm.bpel.tutorial.atm.terminal.WithdrawAction.java

public void actionPerformed(ActionEvent event) {
    Map context = AtmTerminal.getContext();
    AtmPanel atmPanel = (AtmPanel) context.get(AtmTerminal.PANEL);

    // capture amount
    NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
    String amountText = JOptionPane.showInputDialog(atmPanel, "Amount", currencyFormat.format(0.0));
    if (amountText == null)
        return;/* w  ww . j  a  v a 2 s. co m*/

    try {
        // parse amount
        double amount = currencyFormat.parse(amountText).doubleValue();

        // withdraw funds from account
        FrontEnd atmFrontEnd = (FrontEnd) context.get(AtmTerminal.FRONT_END);
        String customerName = (String) context.get(AtmTerminal.CUSTOMER);
        double balance = atmFrontEnd.withdraw(customerName, amount);

        // update atm panel
        atmPanel.setMessage("Your new balance is " + currencyFormat.format(balance));
    } catch (ParseException e) {
        log.debug("invalid amount", e);
        atmPanel.setMessage("Please enter a valid amount.");
    } catch (InsufficientFunds e) {
        log.debug("insufficient funds", e);
        atmPanel.setMessage("I could not fulfill your request.\n" + "Your current balance is only "
                + currencyFormat.format(e.getAmount()));
    } catch (RemoteException e) {
        log.error("remote operation failure", e);
        atmPanel.setMessage("Communication with the bank failed.\n" + "Please log on again.");
        atmPanel.clearActions();
        atmPanel.addAction(new LogOnAction());
        atmPanel.setStatus("connected");
    }
}

From source file:org.jbpm.bpel.tutorial.atm.terminal.GetBalanceAction.java

public void actionPerformed(ActionEvent event) {
    Map context = AtmTerminal.getContext();
    AtmPanel atmPanel = (AtmPanel) context.get(AtmTerminal.PANEL);

    try {//from   ww  w .  ja  va2 s. c o  m
        // get account balance
        FrontEnd atmFrontEnd = (FrontEnd) context.get(AtmTerminal.FRONT_END);
        String customerName = (String) context.get(AtmTerminal.CUSTOMER);
        double balance = atmFrontEnd.getBalance(customerName);

        // update atm panel
        atmPanel.setMessage("Your balance is " + NumberFormat.getCurrencyInstance().format(balance));
    } catch (RemoteException e) {
        log.error("remote operation failure", e);
        atmPanel.setMessage("Communication with the bank failed.\n" + "Please log on again.");
        atmPanel.clearActions();
        atmPanel.addAction(new LogOnAction());
        atmPanel.setStatus("connected");
    }
}

From source file:org.totschnig.myexpenses.Utils.java

/**
 * formats an amount with a currency//from w  ww  . j a v a2  s  .  co  m
 * @param amount
 * @param currency
 * @return formated string
 */
static String formatCurrency(float amount, Currency currency) {
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    nf.setCurrency(currency);
    return nf.format(amount);
}

From source file:com.jetheis.android.makeitrain.fragment.ReportDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);

    AlertDialog.Builder reportBuilder;/*from  w  ww.j a  v  a2  s.co  m*/

    LayoutInflater reportInflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View reportLayout = reportInflater.inflate(R.layout.report_dialog_fragment, null);

    int spent = preferences.getInt(activity.getString(R.string.pref_total_spent), 0);

    NumberFormat nf = NumberFormat.getCurrencyInstance();
    String spentDisplay = nf.format(spent);

    TextView reportText = (TextView) reportLayout.findViewById(R.id.report_dialog_fragment_text_view);
    reportText.setText(activity.getString(R.string.total_spent, spentDisplay));

    reportBuilder = new AlertDialog.Builder(activity);
    reportBuilder.setView(reportLayout);
    reportBuilder.setTitle(R.string.your_spending_report);
    reportBuilder.setPositiveButton(R.string.im_so_cool, null);
    reportBuilder.setNegativeButton(R.string.reset, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int item) {
            dialog.dismiss();
            Editor editor = preferences.edit();
            editor.putInt(activity.getString(R.string.pref_total_spent), 0);
            editor.commit();
        }

    });

    return reportBuilder.create();
}

From source file:com.dgsd.android.ShiftTracker.Adapter.DayAdapter.java

public DayAdapter(Context context, Cursor c, int julianDay) {
    super(context, c, false);
    inflater = LayoutInflater.from(context);
    mJulianDay = julianDay;//from  ww w. j  a v a 2s .  c o  m

    mIs24Hour = DateFormat.is24HourFormat(context);

    mStringBuilder = new StringBuilder();
    mFormatter = new Formatter((mStringBuilder));

    mCurrencyFormatter = NumberFormat.getCurrencyInstance();

    //Caching
    mIdToTimeArray = new SparseArray<String>();
    mIdToPayArray = new SparseArray<String>();

    mShowIncomePref = Prefs.getInstance(context).get(context.getString(R.string.settings_key_show_income),
            true);
}

From source file:org.netxilia.functions.TextFunctions.java

public String DOLLAR(double value, int decimals) {
    NumberFormat format = NumberFormat.getCurrencyInstance();
    format.setMaximumFractionDigits(decimals);
    return format.format(value);
}

From source file:co.edu.unal.pos.gui.PosHadoopJFrame.java

/**
 * Creates new form PosHadoopJFrame// ww w  . j  ava 2  s .c om
 */
public PosHadoopJFrame() {
    initComponents();
    this.setTitle("POS Hadoop");
    currencyFormatter = NumberFormat.getCurrencyInstance();
}

From source file:net.kjmaster.cookiemom.summary.SummarySalesFragment.java

@AfterViews
void afterViews() {
    List<CookieTransactions> list = Main.daoSession.getCookieTransactionsDao().loadAll();
    int total = 0;
    Double totalCash = 0.0;/*from   w  w w  . j a  v a  2s.  co  m*/
    int totalScout = 0;
    int totalBooth = 0;
    Double totalScoutCash = 0.0;
    Double totalBoothCash = 0.0;
    final HashMap<String, Integer> hashMap = new HashMap<String, Integer>();
    for (CookieTransactions cookieTransactions : list) {

        totalCash += cookieTransactions.getTransCash();
        if (cookieTransactions.getTransBoothId() >= 0) {
            totalBooth += (cookieTransactions.getTransBoxes());
            totalBoothCash += cookieTransactions.getTransCash();
        } else {
            if (cookieTransactions.getTransScoutId() >= 0) {
                totalScout += (cookieTransactions.getTransBoxes());
                totalScoutCash += cookieTransactions.getTransCash();
            } else {
                total += cookieTransactions.getTransBoxes();
            }

        }
    }
    NumberFormat fmt = NumberFormat.getCurrencyInstance();
    fmt.setMaximumFractionDigits(0);
    fmt.setMinimumFractionDigits(0);

    ArrayList<Bar> points = new ArrayList<Bar>();
    Bar d = new Bar();

    d.setColor(getResources().getColor(R.color.bar_due));
    d.setName("Due");
    d.setValue(total * 4);
    hashMap.put("Due", total);
    d.setValueString(fmt.format(total * 4));
    Bar d2 = new Bar();
    d2.setColor(getResources().getColor(R.color.bar_cash));
    d2.setName("Cash");
    d2.setValue(totalCash.floatValue());
    d2.setValueString(fmt.format(totalCash));
    hashMap.put("Cash", (totalBooth + totalScout) * -1);
    //        Bar d3=new Bar();
    //        d3.setColor(Color.parseColor("#99CC00"));
    //        d3.setName("Booths");
    //        d3.setValue(totalBooth*-4);
    //        d3.setValueString(fmt.format(totalBooth*4));
    Bar d4 = new Bar();
    d4.setColor(getResources().getColor(R.color.bar_booth));
    d4.setName("Booths");
    d4.setValue(totalBoothCash.floatValue());
    d4.setValueString(fmt.format(totalBoothCash));
    hashMap.put("Booths", totalBooth * -1);
    //     Bar d5=new Bar();
    //        d5.setColor(Color.parseColor("#99CC00"));
    //        d5.setName("Scouts");
    //        d5.setValue(totalScout*-4);
    //        d5.setValueString(fmt.format(totalScout*4));
    Bar d6 = new Bar();
    d6.setColor(getResources().getColor(R.color.bar_scout));
    d6.setName("Scouts");
    d6.setValue(totalScoutCash.floatValue());
    d6.setValueString(fmt.format(totalScoutCash));
    hashMap.put("Scouts", totalScout * -1);
    points.add(d);
    points.add(d2);
    //points.add(d3);
    points.add(d4);
    //       points.add(d5);
    points.add(d6);

    BarGraph g = barGraph;
    g.setBars(points);

    g.setOnBarClickedListener(new BarGraph.OnBarClickedListener() {

        @Override
        public void onClick(int index) {
            legend.setText(hashMap.get(barGraph.getBars().get(index).getName()).toString() + " bxs.");
        }

    });
}

From source file:com.dgsd.android.ShiftTracker.Adapter.WeekAdapter.java

public WeekAdapter(Context context, Cursor c, int julianDay) {
    super(context, c, false);
    inflater = LayoutInflater.from(context);
    mStartingJulianDay = julianDay;// ww  w.  j a va2  s  .co  m
    mRand = new Random();
    mTime = new Time();

    mIs24Hour = DateFormat.is24HourFormat(context);

    mStringBuilder = new StringBuilder();
    mFormatter = new Formatter((mStringBuilder));

    mCurrencyFormatter = NumberFormat.getCurrencyInstance();

    //Caching
    mJdToTitleArray = new SparseArray<String>();
    mIdToTimeArray = new SparseArray<String>();
    mIdToPayArray = new SparseArray<String>();

    mCurrentJulianDay = TimeUtils.getCurrentJulianDay();

    mShowIncomePref = Prefs.getInstance(context).get(context.getString(R.string.settings_key_show_income),
            true);
}

From source file:org.kuali.rice.krad.datadictionary.validation.constraint.CurrencyPatternConstraint.java

/**
 * retrieves a currency formatter instance and sets ParseBigDecimal to true
 * to fix [KULEDOCS-742]/*from   w ww.  j ava 2 s.  c  o  m*/
 *
 * @return CurrencyInstance
 */
private NumberFormat getCurrencyInstanceUsingParseBigDecimal() {
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    if (formatter instanceof DecimalFormat) {
        ((DecimalFormat) formatter).setParseBigDecimal(true);
    }
    return formatter;
}