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 NumberFormat getNumberInstance(Locale inLocale) 

Source Link

Document

Returns a general-purpose number format for the specified locale.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Number number = NumberFormat.getNumberInstance(Locale.JAPAN).parse("25,000.75");
    if (number instanceof Long) {
        System.out.println("Long value: " + number.longValue());
    } else if (number instanceof Double) {
        System.out.println("Double value: " + number.doubleValue());
    }/*from   www.j  ava2s. com*/
}

From source file:Main.java

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

    Number number = NumberFormat.getNumberInstance(Locale.GERMAN).parse("-1.234,56");
    if (number instanceof Long) {
        System.out.println("Long value");
    } else {//www  . j a  v  a2  s  .co  m
        System.out.println("Double value");
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.CANADA);
    System.out.println(numberFormat.getMaximumFractionDigits());
}

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 {

    Locale locale = Locale.GERMAN;
    String string = NumberFormat.getNumberInstance(locale).format(-1234.56);
    System.out.println(string);/*  w ww.  java  2  s.  c  o  m*/
}

From source file:Main.java

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

  Locale locale = Locale.CANADA;
  String string = NumberFormat.getNumberInstance(locale).format(-1234.56); 
  System.out.println(string);//from  w  w w  . ja  v  a2 s  .c o  m

}

From source file:Main.java

public static void main(String[] argv) {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber = 197912.29;

    numberFormat = NumberFormat.getNumberInstance(Locale.US);
    System.out.println("User's number (US): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY);
    System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance();
    System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber));
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber = 1976.0826;

    numberFormat = NumberFormat.getNumberInstance(Locale.US);
    System.out.println("User's number (US): " + numberFormat.format(usersNumber));

}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber = 1976.0826;

    numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY);
    System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber));

}

From source file:ConstantLocaleUsage.java

public static void main(String[] argv) {

    NumberFormat numberFormat = NumberFormat.getInstance();
    numberFormat.setParseIntegerOnly(false);
    double usersNumber;

    if (argv.length == 1)
        try {//from  w w  w . j  av  a 2 s.co  m
            usersNumber = numberFormat.parse(argv[0]).doubleValue();
        } catch (ParseException e) {
            usersNumber = 197912.29;
        }
    else
        usersNumber = 1976.0826;

    numberFormat = NumberFormat.getNumberInstance(Locale.US);
    System.out.println("User's number (US): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY);
    System.out.println("User's number (GERMANY): " + numberFormat.format(usersNumber));
    numberFormat = NumberFormat.getNumberInstance();
    System.out.println("User's number (DEFAULT LOCALE): " + numberFormat.format(usersNumber));
}