NumberFormat Parse Exception
Posted on 2006-04-18
I have a requirement where user can enter positive values like +1 or Negative Values like -1, now the problem is i need to parse it but it is giving an error, i need any way to parse.
Below is the Sample Code :
DecimalFormat df = new DecimalFormat();
Number n = df.parse("+111");
double d = n.doubleValue();
System.out.println(" val - " +d);
Iam Getting an error ..Unparseable number: "+111"
I know if we set df.setPositivePrefix("+"); and then parse it, it works, but its not working if we dont give + its giving again error..
I have a way that is
Number num = decFormat.parse(sValue, new ParsePosition(((sValue.indexOf('+') == -1)?0:1)));
we are just skipping '+', but i dont wanna need this...
does anybody have idea about this...please...