Parsing string currency input as int
I'm trying to take a string input (from a JTextField) and turn it into an int. The input is for currency so I expect people might put commas in there, or even characters by mistake.
This is what I have, with the input being the param:
privateint formatNumber(String s){
NumberFormat nf = NumberFormat.getCurrencyInstance(Locale.US);
ParsePosition p =new ParsePosition(0);
Number n = nf.parse(s,p);
return n.intValue();
}
I am getting NullPointerExceptions, likely because of the ParsePosition. But when I try parse(s), I get ParseException: Unparseable number: "100000".
First, should I be using parse(String s) or parse(String s, ParsePosition pos)?
Second, why am I getting these exceptions?
BTW sorry if this is a multipost, I looked around.

