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

Source Link

Document

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

Usage

From source file:Main.java

public static void main(String args[]) {
    NumberFormat formatter = new DecimalFormat();

    int maxinteger = Integer.MAX_VALUE;

    formatter = new DecimalFormat("0.######E0");
    System.out.println(formatter.format(maxinteger));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.setParseBigDecimal(true);/*from   w  w  w.  ja  v  a  2 s  .  c  o m*/
    BigDecimal value = (BigDecimal) format.parse("1,234.56");
    System.out.println(value);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.setRoundingMode(RoundingMode.CEILING);
    System.out.println(format.format(123456789123.45678));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.setCurrency(Currency.getInstance(Locale.GERMANY));
    System.out.println(format.clone());

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.setCurrency(Currency.getInstance(Locale.GERMANY));
    System.out.println(format.getCurrency());

}

From source file:Main.java

public static void main(String[] args) {
    NumberFormat formatter = new DecimalFormat();
    Locale locale = Locale.getDefault();
    System.out.println("Locale = " + locale);
    System.out.println(formatter.format(123.123));

    locale = Locale.ITALY;/*w  w w.j  av  a 2  s  . co m*/
    Locale.setDefault(locale);
    formatter = new DecimalFormat();
    System.out.println("Locale = " + locale);
    System.out.println(formatter.format(123.123));
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    DecimalFormat format = new DecimalFormat();
    format.setCurrency(Currency.getInstance(Locale.GERMANY));

    DecimalFormat format1 = new DecimalFormat();

    System.out.println(format1.equals(format));
}

From source file:Main.java

public static void main(String args[]) {
    NumberFormat formatter = new DecimalFormat();

    int maxinteger = Integer.MAX_VALUE;
    System.out.println(maxinteger);
    formatter = new DecimalFormat("0.######E0");
    System.out.println(formatter.format(maxinteger));

    formatter = new DecimalFormat("0.#####E0");
    System.out.println(formatter.format(maxinteger));

    int mininteger = Integer.MIN_VALUE;
    System.out.println(mininteger);

    formatter = new DecimalFormat("0.######E0");
    System.out.println(formatter.format(mininteger));

    formatter = new DecimalFormat("0.#####E0");
    System.out.println(formatter.format(mininteger));

    double d = 0.12345;
    formatter = new DecimalFormat("0.#####E0");
    System.out.println(formatter.format(d));

    formatter = new DecimalFormat("000000E0");
    System.out.println(formatter.format(d));
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println("Enter a number.");
    double numberFromConsole;
    try {//from www . java 2s.c  o  m
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        String s = br.readLine();
        DecimalFormat df = new DecimalFormat();
        Number n = df.parse(s);
        numberFromConsole = n.doubleValue();
    } catch (IOException e) {
        numberFromConsole = 0;
    } catch (ParseException e) {
        numberFromConsole = 0;
    }
    System.out.println(numberFromConsole);
}

From source file:com.enitalk.controllers.paypal.Usd.java

public static void main(String[] args) throws IOException, ParseException {

    String rs = Request.Get("http://www.cbr.ru/scripts/XML_daily.asp")
            .addHeader("Content-type", "application/xml;charset=utf-8").execute().returnContent()
            .asString(Charset.forName("windows-1251"));

    Pair<AutoPilot, VTDNav> bb = getNavigator(rs.getBytes());
    String change = getChange(bb.getLeft(), bb.getRight());

    System.out.println("Rs " + change);
    DecimalFormat df = new DecimalFormat();
    DecimalFormatSymbols symbols = new DecimalFormatSymbols();
    symbols.setDecimalSeparator(',');
    df.setDecimalFormatSymbols(symbols);
    BigDecimal dd = BigDecimal.valueOf(df.parse(change).doubleValue()).setScale(2, RoundingMode.CEILING);
    System.out.println("Dd " + dd);
}