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

NumberFormat parse throws exceptions on 0

XMLWordPrintable

    • b01
    • generic, x86, sparc
    • generic, solaris_2.5, solaris_2.5.1, solaris_9, windows_nt
    • Not verified

        Shouldn't the following code work? It does under 1.1, but 1.1.1 throws
        an exception.

        import java.text.NumberFormat;
         
        public class CurrTest {
         
          public static void main(String args[]) {
            double testnum = 345.6789;
            long longnum = 23234567;
         
            try {
         
              NumberFormat cf = NumberFormat.getCurrencyInstance();
              System.out.println("cf: " + cf);
              Number tnum = cf.parse("$0.00");
              System.out.println("tnum: " + tnum);
              String result = new Double(tnum.doubleValue()).toString();
              System.out.println("result: " + result);
         
            } catch(Exception e) {
              System.out.println("exception: " + e.getMessage());
              e.printStackTrace();
            }
         
            try {
         
              NumberFormat cf = NumberFormat.getNumberInstance();
              System.out.println("cf: " + cf);
              Number tnum = cf.parse("0.00");
              System.out.println("tnum: " + tnum);
              String result = new Double(tnum.doubleValue()).toString();
              System.out.println("result: " + result);
         
            } catch(Exception e) {
              System.out.println("exception: " + e.getMessage());
              e.printStackTrace();
            }
         
          }
        }

              bcbeck Brian Beck (Inactive)
              bcbeck Brian Beck (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: