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

BigDecimal.stripTrailingZeros() has no effect on zero itself ("0.0")

    Details

    • Subcomponent:
    • Resolved In Build:
      b100
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Verified

      Description

      FULL PRODUCT VERSION :
      java version "1.5.0_06"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
      Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      BigDecimal.stripTrailingZeros() had no effect on padded versions of 0, such as "0.0000"

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the included program with "java -classpath . BigDecimalTest 0.000000"
      or "java -classpath . BigDecimalTest .000000"

      You can use any number in the command line, and it works as expected as long as there is at least one non-zero digit in the input.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Starting decimal = 0.000000 scale = 6
      Ending decimal = 0 scale = 0

      ACTUAL -
      Starting decimal = 0.000000 scale = 6
      Ending decimal = 0.000000 scale = 6

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.math.BigDecimal;

      public class BigDecimalTest {

          public static void main(String args[]) {
              BigDecimal dec = new BigDecimal(args[0]);
              System.out.print("Starting decimal = " + dec.toPlainString());
              System.out.println(" scale = " + dec.scale());
              dec = dec.stripTrailingZeros();
              System.out.print("Ending decimal = " + dec.toPlainString());
              System.out.println(" scale = " + dec.scale());

          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      you can work around it with the something like the following:

      BigDecimal zero = new BigDecimal("0");
      if ( someBigDecimal.compareTo(zero) == 0 ) {
          someBigDecimal = zero;
      } else {
          someBigDecimal = someBigDecimal .stripTrailingZeros();
      }

        Issue Links

          Activity

          Hide
          darcy Joe Darcy added a comment -
          BT2:EVALUATION

          Will investigate.
          Show
          darcy Joe Darcy added a comment - BT2:EVALUATION Will investigate.
          Hide
          bpb Brian Burkhalter added a comment -
          Could not find anything on grepcode.com or code.google.com which fixing this to return BigDecimal.ZERO for magnitude 0 would break.
          Show
          bpb Brian Burkhalter added a comment - Could not find anything on grepcode.com or code.google.com which fixing this to return BigDecimal.ZERO for magnitude 0 would break.
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/2ee772cda1d6
          User: robm
          Date: 2013-07-10 18:55:06 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/2ee772cda1d6 User: robm Date: 2013-07-10 18:55:06 +0000
          Hide
          hgupdate HG Updates added a comment -
          URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/2ee772cda1d6
          User: lana
          Date: 2013-07-23 18:11:27 +0000
          Show
          hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/2ee772cda1d6 User: lana Date: 2013-07-23 18:11:27 +0000

            People

            • Assignee:
              bpb Brian Burkhalter
              Reporter:
              ndcosta Nelson Dcosta
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: