|
Parsing a number using a NumberFormat
import java.text.NumberFormat;
import java.text.ParseException;
/*
* Parse a number using a NumberFormat.
*/
public class NumFormatParse {
//+
/** A number to parse */
public static final String input = "4096.251";
//-
/** The main (and only) method in this class. */
public static void main(String[] av) {
//+
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!");
}
}
}
__________________
Want to make your IDE the best? To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. to our beloved Java Forums! (closes on July 27, 2008)
|