Concerning
Number parsed = numberFormat.parse("4,5.6dfhf");
you can use NumberFormat.parse (String source, ParsePosition pos) and check if the position at which it parsed is really the last position of the string.
Also, on issue 4.5.6, you can try to set the grouping setGroupingUsed (boolean newValue) as I think this is the problem caused by '.' The character is a grouping symbol in the locale.
It should be something like
NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.getDefault()); numberFormat.setGroupingUsed(false); ParsePosition pos; String nString = "4,5.6dfhf"; Number parsed = numberFormat.parse(nString, pos); if (pos.getIndex() == nString.length()) // pos is set AFTER the last parsed position System.out.println("parsed = " + parsed); else // Wrong
Manuel miranda
source share