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 args[]) {
    double d = 123456.7890;
    DecimalFormat df = new DecimalFormat("#####0.00");
    System.out.println(df.format(d));
}

From source file:Main.java

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

    DecimalFormat formatter = new DecimalFormat("#E0"); // exponent can be any
                                                        // value
    String s = formatter.format(-1234.567);
    System.out.println(s);/*  w  w w  .java 2  s.  co  m*/

    s = formatter.format(-.1234567);
    System.out.println(s);
}

From source file:Main.java

public static void main(String[] args) {
    NumberFormat formatter = new DecimalFormat("0000000");
    String number = formatter.format(2500);

    System.out.println("Number with lading zeros: " + number);
}

From source file:Main.java

public static void main(String[] args) {
    double myVal = 12.456;
    DecimalFormat leftside = new DecimalFormat("000.0000000000");
    System.out.println(leftside.format(myVal));
}

From source file:Main.java

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

    DecimalFormat formatter = new DecimalFormat("00E00");
    String s = formatter.format(-1234.567);
    System.out.println(s);//w  w  w . jav a2  s . c  o m

    formatter = new DecimalFormat("000E00");

    s = formatter.format(-1234.567); // -123E01
    System.out.println(s);

    formatter = new DecimalFormat("0000000000E0");
    s = formatter.format(-1234.567); // -1234567000E-6
    System.out.println(s);
}

From source file:Main.java

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

    Format formatter = new DecimalFormat("'abc'#");
    String s = formatter.format(-1234.567);
    System.out.println(s);//  w  w w. j av a2 s  . co  m
}

From source file:Main.java

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

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

From source file:Main.java

public static void main(String[] args) {
    double numberToRound = 12345.6789;

    DecimalFormat df = new DecimalFormat("0.000");
    System.out.println("Rounded number = " + df.format(numberToRound));

    System.out.println(String.format("Rounded number = %.3f", numberToRound));

}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("##00");
    String s = formatter.format(0); // 00
    System.out.println(s);/*w ww .  jav a2s  . c o m*/
}

From source file:Main.java

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

    NumberFormat formatter = new DecimalFormat("0.00");
    String s = formatter.format(-.567); // -0.57
    System.out.println(s);/*  w w  w . j  a  v a2  s.c  om*/
}