Example usage for java.text NumberFormat getNumberInstance

List of usage examples for java.text NumberFormat getNumberInstance

Introduction

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

Prototype

public static final NumberFormat getNumberInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:Main.java

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

    String string = NumberFormat.getNumberInstance().format(-1234.56);
    System.out.println(string);//from  w w  w. j  a  va2 s .c  o m
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    System.out.println(numberFormat.parse("123"));
}

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.getNumberInstance();
    System.out.println(numberFormat.getMaximumFractionDigits());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    System.out.println(numberFormat.parseObject("123", new ParsePosition(0)));
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    System.out.println(numberFormat.parse("123", new ParsePosition(0)));
}

From source file:NumberFormatRounding.java

public static void main(String[] args) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);/*from  ww  w .  jav  a  2 s.c o  m*/
    nf.setRoundingMode(RoundingMode.HALF_DOWN);
    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

}

From source file:NumberFormatRounding.java

public static void main(String[] args) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);//from  www.  j  a v a  2  s . c o  m

    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

}

From source file:NumberFormatRounding.java

public static void main(String[] args) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);/*from  w w w .  java  2 s  . c  o  m*/
    nf.setRoundingMode(RoundingMode.CEILING);
    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

}

From source file:NumberFormatRounding.java

public static void main(String[] args) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    nf.setMaximumFractionDigits(2);/*from  w w  w .  jav a2  s  .c  o m*/
    nf.setRoundingMode(RoundingMode.FLOOR);
    System.out.println("Default rounding mode: " + nf.getRoundingMode());
    System.out.println("123.454 rounds to " + nf.format(123.454));
    System.out.println("123.455 rounds to " + nf.format(123.455));
    System.out.println("123.456 rounds to " + nf.format(123.456));
    System.out.println();

}