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 df = new DecimalFormat("#,.00;(#,.00)");
    System.out.println(df.format(7123.00));

}

From source file:Main.java

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

    DecimalFormat df = new DecimalFormat("\u00a4#,##0.00");
    System.out.println(df.format(4232.19));
    System.out.println(df.format(-4232.19));
}

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) {

    DecimalFormat formatter = new DecimalFormat("###E0");
    String s = formatter.format(-1234.567); // -1.23E3
    System.out.println(s);//from  www . j  a va  2 s  .  com
    s = formatter.format(-123.4567); // -123E0
    System.out.println(s);
    s = formatter.format(-12.34567); // -12.3E0
    System.out.println(s);
    s = formatter.format(-1.234567); // -12.3E0
    System.out.println(s);
    s = formatter.format(-.1234567); // -123E-3
    System.out.println(s);
}

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);/*from www .  jav a 2  s .co  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[] 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 {
    DecimalFormat format = new DecimalFormat();
    format.setMultiplier(100);//  w  w w .j ava2  s  . c  o m
    System.out.println(format.format(123456789.12345678));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.applyPattern("##.##");
    System.out.println(format.format(-123456789.12345678));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();

    format.setGroupingSize(4);/*from  w w w  .j a va2  s.co  m*/

    System.out.println(format.format(123456789.12345678));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.setParseBigDecimal(true);//from w  ww .jav a2s  .c  o  m
    System.out.println(format.format(12345678912345678L));

}