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[] args) {
    int areaCode = 123;
    int exchangeCode = 456;

    NumberFormat nf3 = new DecimalFormat("0000");

    System.out.println(nf3.format(areaCode) + "-" + nf3.format(exchangeCode));
}

From source file:Mortgage.java

public static void main(String[] args) {
    double payment = Math.random() * 1000;
    System.out.println("Your payment is ");
    NumberFormat nf = NumberFormat.getCurrencyInstance();
    System.out.println(nf.format(payment));
}

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);//from   w ww . j  a  va2s  . c  om
    s = formatter.format(-1234567.890);
    System.out.println(s);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    System.out.println(numberFormat.format(100000000));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getPercentInstance();
    System.out.println(numberFormat.format(99.999999));

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat formatter = NumberFormat.getNumberInstance(Locale.ITALY);
    String number = formatter.format(123456789.12);
    System.out.println("Number in Italy: " + number);
    formatter = NumberFormat.getNumberInstance(Locale.JAPAN);
    number = formatter.format(123456789.12);
    System.out.println("Number in Japan: " + number);
}

From source file:Main.java

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

    NumberFormat nf = NumberFormat.getCurrencyInstance();

    System.out.println("currency format: " + nf.format(1234.56) + " " + nf.format(-1234.56));
}

From source file:Main.java

public static void main(String args[]) {
    NumberFormat nf = NumberFormat.getInstance();

    System.out.println("Default format: " + nf.format(1234567.678));

    nf.setMaximumFractionDigits(2);/*  w  ww. j  a  va2 s .  c  o m*/

    System.out.println("Format with two decimal places: " + nf.format(1234567.678));

}

From source file:Main.java

public static void main(String args[]) {
    NumberFormat nf = NumberFormat.getInstance();

    System.out.println("Default format: " + nf.format(1234567.678));

    nf.setGroupingUsed(false);/* ww w  .  ja  v a2  s .com*/

    System.out.println("Format without groupings: " + nf.format(1234567.678));

}

From source file:NumberFormatApp.java

public static void main(String args[]) {
    NumberFormat format = NumberFormat.getCurrencyInstance(Locale.getDefault());
    String formattedCurrency = format.format(1000000);
    System.out.println(formattedCurrency);
}