Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4143343

java.text.DecimalFormat.parse() works wrong when zeroDigit is not set to 0

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      Name: dfC67450 Date: 05/28/98



      java.text.DecimalFormat.parse(String str, ParsePosition pp) parses
      wrong if zeroDigit field of DecimalFormatSymbols field is not set to 0.
      It uses two sets of digit representation:
      '0'..'9' and zeroDigit .. zeroDigit + 9.
       
      Here is the test demonstrating the bug:

      -----------------TestPZ.java------------------------
      import java.text.*;
      import java.util.*;

      public class Test {
          public static void main (String args[]){
            DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.ENGLISH);
            dfs.setZeroDigit('n');
            DecimalFormat df = new DecimalFormat("#,##0", dfs);
            String formatted123 = df.format(123);
            String text123123 = formatted123 + "123";
            Number parsed = df.parse(text123123, new ParsePosition(0));
            System.out.println("zeroDigit: " + dfs.getZeroDigit());
            System.out.println("format(123): " + formatted123);
            System.out.println("parse(" + text123123 +") : " + parsed);
            if (parsed != null) {
              System.out.println("test failed, parse should return null");
            } else {
              System.out.println("test passed");
            }
          }
      }
      ---------Output from the test---------------------
      zeroDigit: n
      format(123): opq
      parse(opq123) : 123123
      test failed, parse should return null
      --------------------------------------------------

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            aliusunw Alan Liu (Inactive)
            Reporter:
            dfazunensunw Dmitri Fazunenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: