In the code below, I am wondering why an exception will be thrown :
import java.text.*;
class NumFormat
{
public static void main(String[] args)throws Exception{
String s = "123.456xyz";
NumberFormat nf = NumberFormat.getInstance();
System.out.println(nf.parse(s));
nf.setMaximumFractionDigits(2);
System.out.println(nf.format(s));
}
}
format()expects a number to format, where asparse()returns a number from a string.Will give you the result you were expecting.
References:
format() documentation
parse() documentation