Example usage for java.text NumberFormat format

List of usage examples for java.text NumberFormat format

Introduction

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

Prototype

public final String format(long number) 

Source Link

Document

Specialization of format.

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 w w  w  .  ja  va2  s .  co m
}

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);/*from   w ww  . j  a v a 2s.co 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);/*from ww w .  j  a  va 2  s.  com*/
}

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);/*from   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);/*w w w.  jav  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 w  w  .  j ava  2  s  . c om
}

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);//  ww w .j  av  a  2s.  com

}

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.java2  s  .c  o  m*/
}

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 va  2  s.  co  m
    // number was rounded up

}

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);
}