Ticket #4927 (closed enhancement: duplicate)

SVN Diffs for #4927

 

Opened 3 years ago

Last modified 4 months ago

Require a more restricted parse for NumberFormat

Reported by: yangrw(at)cn.ibm.com Assigned to: yoshito
Priority: assess Milestone: UNSCH
Component: formatting Version: 3.2
Keywords: Cc:
Load: Xref: 4963 5206
Java Version: ibmjdk1.3.x Operating System: win32
Project (C/J): ICU4J Weeks:
Review:

Description (Last modified by grhoten)

When parse a string with grouping characters, user may expect that only well formatted string can be parsed. This ability can detect some inattentive errors. For example, type 1.2 (one point two) as 1,2 (one comma two). One project has postponed a bug due to this limitation.

public class Sutdy { public static void main(String[] args) throws ParseException { //String str = "1,2"; String str = "1,23,456,7890"; Locale locale = Locale.ENGLISH; NumberFormat nfa = NumberFormat.getInstance(locale); DecimalFormat nf; if (nfa instanceof DecimalFormat){

nf = (DecimalFormat) nfa;

} else {

System.err.println("wrong."); return;

} System.out.println(nf.toPattern()); Number n = nf.parse(str,new ParsePosition(0)); System.out.println(n); System.out.println(nf.format(n)); } }

Attachments

Change History

12/31/69 17:38:27 changed by auditor

  • Wed Dec 7 08:30:04 2005 grhoten changed notes2: xref: "" to "4963",
  • Thu Dec 15 10:07:38 2005 schererm changed notes2: assign: "" to "mark, george", priority: "" to "high", summmary: "" to "RFE: Require a more restricted parse for NumberFormat", comments: "" to "discuss!",
  • Mon Dec 19 11:46:22 2005 weiv changed notes2: comments: "discuss!" to "",
  • Wed Mar 22 23:47:33 2006 grhoten changed notes2: assign: "mark, george" to "george",
  • Tue May 23 15:33:26 2006 dougfelt changed notes2: xref: "4963" to "4963 6206",
  • Tue May 23 15:33:37 2006 dougfelt changed notes2: xref: "4963 6206" to "4963 5206",

10/03/07 21:32:32 changed by grhoten

  • load changed.
  • description changed.
  • summary changed from RFE: Require a more restricted parse for NumberFormat to Require a more restricted parse for NumberFormat.
  • keywords deleted.
  • weeks changed.
  • revw changed.

03/05/08 20:30:34 changed by grhoten

  • owner changed from grhoten to yoshito.

07/09/08 15:49:44 changed by yoshito

  • priority changed from major to assess.
  • milestone changed from UNSCH to 4.2.

07/18/08 14:20:56 changed by yoshito

  • status changed from new to closed.
  • resolution set to duplicate.
  • milestone changed from 4.2 to UNSCH.

This feature was already implemented by #5206. With setParseString(true), the sample code above works as the bug author expected. So I'll close this as a duplicate.


Add/Change #4927 (Require a more restricted parse for NumberFormat)




Anti spam check: