Example usage for java.text DecimalFormat format

List of usage examples for java.text DecimalFormat format

Introduction

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

Prototype

public final String format(double number) 

Source Link

Document

Specialization of format.

Usage

From source file:Main.java

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

    DecimalFormat formatter = new DecimalFormat("0.0E0");
    String s = formatter.format(-1234.567); // -1.2E3
    System.out.println(s);//from ww w  .j a  v a 2 s . c  o m
}

From source file:Main.java

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

    DecimalFormat df = new DecimalFormat("#%");
    System.out.println(df.format(0.19));
    System.out.println(df.format(-0.19));
}

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);/*ww  w  . j  ava 2s. c o  m*/
}

From source file:Main.java

public static void main(String args[]) {
    DecimalFormat df = new DecimalFormat("0000000000000000");
    String z = df.format(123456);
    System.out.println(z);//ww  w  .j  av  a  2  s.  c o  m
}

From source file:Main.java

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

    DecimalFormat df = new DecimalFormat("#%");
    System.out.println(df.format(0.19));
    System.out.println(df.format(-0.19));
    System.out.println(df.format(-0.009));
    System.out.println(df.format(-12.009));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat formatter = new DecimalFormat("000E00");

    String s = formatter.format(-1234.567); // -123E01
    System.out.println(s);/*  w w w  .  j a v a 2  s .co  m*/
}

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");
    String s = formatter.format(-1234.567);
    System.out.println(s);/*from  w w  w  .  j a  va2s .  com*/
    s = formatter.format(-123.4567);
    System.out.println(s);
    s = formatter.format(-12.34567);
    System.out.println(s);
}

From source file:Main.java

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

    DecimalFormat formatter = new DecimalFormat("00.00E0");
    String s = formatter.format(-1234.567); // -12.35E2
    System.out.println(s);/*w w  w.  java 2s .com*/
    s = formatter.format(-.1234567); // -12.35E-2
    System.out.println(s);
}

From source file:Main.java

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

    DecimalFormat formatter = new DecimalFormat("0000000000E0");
    String s = formatter.format(-1234.567); // -1234567000E-6
    System.out.println(s);/*w w w .  ja v a  2s .  c om*/
}