NumberFormat: parse(String source) : NumberFormat « java.text « Java by API






NumberFormat: parse(String source)

 
/*
4096.251 parses as 4096.251 and formats as 4,096.251
 */
import java.text.NumberFormat;
import java.text.ParseException;

public class MainClass {

  public static void main(String[] av) {

    String input = "4096.251";
    NumberFormat defForm = NumberFormat.getInstance();

    try {
      Number d = defForm.parse(input);
      System.out.println(input + " parses as " + d + " and formats as " + defForm.format(d));
    } catch (ParseException pe) {
      System.err.println(input + "not parseable!");
    }
  }

}

           
         
  








Related examples in the same category

1.NumberFormat: format(Object obj)
2.NumberFormat.getCurrencyInstance();
3.NumberFormat: getCurrencyInstance(Locale.UK)
4.NumberFormat: getInstance()
5.NumberFormat: getNumberInstance()
6.NumberFormat: getNumberInstance(Locale.FRENCH)
7.NumberFormat: getIntegerInstance(Locale.ITALIAN)
8.NumberFormat: getNumberInstance(Locale inLocale)
9.NumberFormat: getPercentInstance(Locale inLocale)
10.NumberFormat.setMaximumFractionDigits(int newValue)
11.NumberFormat: setMinimumFractionDigits(int newValue)
12.NumberFormat: setMinimumIntegerDigits(int newValue)
13.NumberFormat: setParseIntegerOnly(boolean value)