Example usage for java.text DecimalFormat DecimalFormat

List of usage examples for java.text DecimalFormat DecimalFormat

Introduction

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

Prototype

public DecimalFormat(String pattern) 

Source Link

Document

Creates a DecimalFormat using the given pattern and the symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat(".00");
    String s = formatter.format(-.567); // -.57
    System.out.println(s);//from ww  w.ja  v  a 2  s  .c om
}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("#.000000");
    String s = formatter.format(-1234.567);
    System.out.println(s);/*from   ww w. ja  v a2  s. c om*/
}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("0E0");
    String s = formatter.format(-1234.567);
    System.out.println(s);//  w  w  w .  jav  a  2 s  . c o m
}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat(".######");
    String s = formatter.format(-1234.567); // -1234.567
    System.out.println(s);// w  ww .  j a v  a  2 s  .c  o m

}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("#.######");
    String s = formatter.format(-1234.567); // -1234.567
    System.out.println(s);/*from  ww  w  . j  a  v a 2 s  . c om*/

}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("000000");
    String s = formatter.format(-1234.567);
    System.out.println(s);/*from w  ww.j  a v  a 2  s.  c  o  m*/
    // number was rounded up

}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("'#'#");

    String s = formatter.format(-1234.567);

    System.out.println(s);/* ww w .  j  a v  a2  s  .  c  o  m*/
}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("#,###,###");
    String s = formatter.format(-1234.567);
    System.out.println(s);/*from   w  w w  .  ja  v a  2  s.  c  om*/
    s = formatter.format(-1234567.890);
    System.out.println(s);

}

From source file:Main.java

public static void main(String args[]) {
    double d = 123456.7890;
    DecimalFormat df = new DecimalFormat("#####0.00");
    DecimalFormatSymbols dfs = df.getDecimalFormatSymbols();

    dfs.setDecimalSeparator('.');
    df.setDecimalFormatSymbols(dfs);//  ww  w.  j  a va2 s  .  c  o m
    System.out.println(df.format(d));
}

From source file:Main.java

public static void main(String[] args) {
    double money = 123456789.12;

    NumberFormat formatter = new DecimalFormat("#0.00");

    System.out.println(money);//from w ww .j  av  a 2 s  . co  m

    System.out.println(formatter.format(money));
}