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:NumberFormatApp.java

public static void main(String args[]) {
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.getDefault());
    String formattedCurrency = format.format(1000000);
    System.out.println(formattedCurrency);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    Number number = NumberFormat.getCurrencyInstance(Locale.GERMANY).parse("$123.45");
    if (number instanceof Long) {
        System.out.println("Long value");
    } else {/* w  w w .j av a  2 s  . c o  m*/
        System.out.println("Double value");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.CANADA);
    System.out.println(numberFormat.getCurrency().getDisplayName());
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    // Format/*from   ww w  . j a va  2  s. c  o m*/
    Locale locale = Locale.GERMANY;
    String string = NumberFormat.getCurrencyInstance(locale).format(123.45);

}

From source file:Main.java

public static void main(String[] args) {
    BigDecimal payment = new BigDecimal("12345.67");
    NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US);
    double doublePayment = payment.doubleValue();
    String s = n.format(doublePayment);
    System.out.println(s);/*  w  w  w .  ja  v a  2 s.  c om*/
}

From source file:Main.java

public static void main(String[] args) {
    double value = 1234567.89;

    System.out.println("Unformatted: " + value + "\n");

    Locale locales[] = { Locale.US, Locale.FRANCE, Locale.GERMANY, Locale.JAPAN, new Locale("fr", "FR", "EURO"),
            new Locale("de", "DE", "EURO") };

    for (int i = 0; i < locales.length; i++) {
        NumberFormat nf = NumberFormat.getCurrencyInstance(locales[i]);

        System.out.println("Formatted for " + locales[i] + ": " + nf.format(value));
    }//from  ww w  .  ja v a2  s . c o m
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {

    JFrame frame = new JFrame("Number Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = new Font("SansSerif", Font.BOLD, 16);

    JLabel label;/*from  ww w .j av  a2 s.  c  o  m*/
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format currency = NumberFormat.getCurrencyInstance(Locale.UK);
    label = new JLabel("UK Currency:");
    input = new JFormattedTextField(currency);
    input.setValue(2424.50);
    input.setColumns(20);
    input.setFont(font);
    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);
    frame.add(panel);

    frame.pack();
    frame.setVisible(true);
}

From source file:NumberInputSampleLocaleUK.java

public static void main(String args[]) {
    JFrame frame = new JFrame("Number Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Font font = new Font("SansSerif", Font.BOLD, 16);

    JLabel label;/*from w  ww  .j  ava2 s  .  co m*/
    JFormattedTextField input;
    JPanel panel;

    BoxLayout layout = new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS);
    frame.setLayout(layout);

    Format currency = NumberFormat.getCurrencyInstance(Locale.UK);
    label = new JLabel("UK Currency:");
    input = new JFormattedTextField(currency);
    input.setValue(2424.50);
    input.setColumns(20);
    input.setFont(font);

    panel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    panel.add(label);
    panel.add(input);
    frame.add(panel);

    frame.add(new JTextField());
    frame.pack();
    frame.setVisible(true);
}

From source file:Main.java

public static String getFormattedValue(double value) {

    NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("pt", "BR"));

    return nf.format(value);
}

From source file:Main.java

public static String getMonetaryValue(Double value) {
    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.getDefault());
    return numberFormat.format(value);
}