Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

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

Prototype

public static final NumberFormat getInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

public static void main(String args[]) {
    NumberFormat nf = NumberFormat.getInstance();

    System.out.println("Default format: " + nf.format(1234567.678));

    nf.setMaximumFractionDigits(2);//from   ww  w.  ja v a  2 s  .  c om

    System.out.println("Format with two decimal places: " + nf.format(1234567.678));

}

From source file:Main.java

public static void main(String args[]) {
    NumberFormat nf = NumberFormat.getInstance();

    System.out.println("Default format: " + nf.format(1234567.678));

    nf.setGroupingUsed(false);/*from   w w  w  . j av a2s  .  c  om*/

    System.out.println("Format without groupings: " + nf.format(1234567.678));

}

From source file:Main.java

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

From source file:Main.java

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

    NumberFormat nf = NumberFormat.getInstance();

    nf.setMinimumFractionDigits(2);/*w w  w  . j av a 2  s  . c  om*/

    System.out.println("Format with two decimal places: " + nf.format(1234567.678));

}

From source file:Main.java

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

    NumberFormat nf = NumberFormat.getInstance();

    nf.setMinimumFractionDigits(2);// w w  w.  ja  v a2s  .c  o  m

    System.out.println("Format with two decimal places: " + nf.format(1234567.678));
    System.out.println("Format with two decimal places: " + nf.format(1234567.6));

}

From source file:Main.java

public static void main(String[] argv) {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber = 197912.29;

    numberFormat = NumberFormat.getNumberInstance(Locale.US);
    System.out.println("User's number (US): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY);
    System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance();
    System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber));
}

From source file:Main.java

public static void main(String[] args) {
    NumberFormat formatter;// w w  w. jav  a  2s.  c  o  m
    // Get number formatter for default locale
    formatter = NumberFormat.getInstance();
    System.out.println(formatter.format(12312.123123));
}

From source file:Main.java

public static void main(String[] argv) {
    DecimalFormat df = (DecimalFormat) NumberFormat.getInstance();
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setZeroDigit('\u0660');
    df.setDecimalFormatSymbols(dfs);/*  w ww  .  j  av  a  2 s . c  o m*/

    System.out.println(df.format(1234567.89));
}

From source file:MainClass.java

public static void main(String[] argv) {
    NumberFormat nf = NumberFormat.getInstance();
    if (nf instanceof DecimalFormat) {
        DecimalFormat df = (DecimalFormat) nf;

        DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

        dfs.setCurrencySymbol("AD$");

        df.setDecimalFormatSymbols(dfs);

        df.applyPattern("\u00a4#,###.##");
    }/*from   w  ww  .  j a  v  a2s  . c  o m*/

    System.out.println(nf.format(1234.56));

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber = 1976.0826;

    numberFormat = NumberFormat.getNumberInstance();
    System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber));

}