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

new BigDecimal(String) looses the "-" sign in some signed strings

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.1
    • core-libs
    • None
    • x86
    • windows_95



      Name: mc57594 Date: 03/06/97


      // BigBug.java - Error in BigDecimal.
      /**
      Negative sign is lost when coverting a string representing
      negative cents with no dollars from a named String variable
      to a BigDecimal
      */
      import java.math.*;
      class BigBug {
      public static void main(String[] args) {
      String tok = "-0.70";
      String toka = "-.70";
      BigDecimal bigb = new BigDecimal(tok);
      bigb.setScale(2, BigDecimal.ROUND_HALF_UP);
      BigDecimal bigc = new BigDecimal(toka);
      bigc.setScale(2, BigDecimal.ROUND_HALF_UP);

      System.out.println("bigb is new toka -0.70 = " + bigb
                                        + “; Error: Sign lost”);
      System.out.println("bigc is new toka -.70 = " + bigc
                                        + “; OK, Sign preserved.”);

      }
      }



      company - TG Software Pty Ltd , email - ###@###.###
      ======================================================================

            jjb Josh Bloch (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: