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.

[1005 byte] By [canman88a] at [2007-11-27 4:04:09]
# 1
Why dont you try Integer.parseInt(String) ?
hcubeindiaa at 2007-7-12 9:09:00 > top of Java-index,Java Essentials,Java Programming...
# 2
another approach would be the following one:define a regular expression for the number format (eg [0-9]*,[0-9][0-9])when validatingif (field matches regex)// do the processelse// alert the user on the format expected
calvino_inda at 2007-7-12 9:09:00 > top of Java-index,Java Essentials,Java Programming...