More strict number parsing
--------------------------
Key: STS-390
URL: http://mc4j.org/jira/browse/STS-390
Project: Stripes
Issue Type: Improvement
Components: Validation
Affects Versions: Release 1.4.3
Reporter: Karel Kolman
Assigned To: Tim Fennell
NumberTypeConverterSupport should check for number parsing errors by other
means than by catching ParseExceptions only.
Let's say I'm entering the values 0.2 and 0,2 (with different decimal
separators) into a BigDecimal field. The value is set to either 0 or 0.2
according to the locale Stripes selects. The case when 0.2 gets parsed into 0
without producing an error is causing me trouble.
The NumberTypeConverterSupport parsing code is:
try { return format.parse(input); }
catch (ParseException pe) { /* Do nothing. */ }
I think it should be something like this:
ParsePosition parsePos = new ParsePosition(0);
Number number = format.parse(input, parsePos);
if (number != null && input.length == parsePos.getIndex()) return number;
IMHO using NumberFormat.parse(String source, ParsePosition parsePosition) is a
better alternative to parse(String source)
(also see this article
http://www.ibm.com/developerworks/java/library/j-numberformat/
)
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://mc4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development