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

Inconsistent behaviour of BigDecimal.stripTrailingZeros()

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • P4
    • Resolution: Duplicate
    • 6
    • None
    • core-libs
    • x86
    • windows_xp

    Description

      FULL PRODUCT VERSION :
      java version "1.6.0_17"
      Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
      Java HotSpot(TM) Client VM (build 14.3-b01, mixed mode, sharing)

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

      A DESCRIPTION OF THE PROBLEM :
      Calling stripTrailingZeros() e.g. on value "1.00" leads to "1" as expected, but for value "0.00" (or "0.0" etc.) it always returns the given value without stripping the trailing zeros.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      (new BigDecimal("1.00")).stripTrailingZeros()
      //Result: 1

      (new BigDecimal("1.10")).stripTrailingZeros()
      //Result: 1.1

      (new BigDecimal("0.00")).stripTrailingZeros()
      //Result: 0.00

      (new BigDecimal("0.0")).stripTrailingZeros()
      //Result: 0.0

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      (new BigDecimal("0.00")).stripTrailingZeros()
      //Expected result: 0

      (new BigDecimal("0.0")).stripTrailingZeros()
      //Expected result: 0

      ACTUAL -
      (new BigDecimal("0.00")).stripTrailingZeros()
      //Result: 0.00

      (new BigDecimal("0.0")).stripTrailingZeros()
      //Result: 0.0

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class StripTrailingZerosTest {

      /**
      * @param args
      */
      public static void main(String[] args) {
      // for value 1.00 the behaviour is as expected:
      BigDecimal bd = new BigDecimal("1.00");
      System.out.println("stripTrailingZeros on 1.00: " + bd.stripTrailingZeros().toString());

      // for value 0.00 it is not:
      BigDecimal bdZero = new BigDecimal("0.00");
      System.out.println("stripTrailingZeros on 0.00: " + bdZero.stripTrailingZeros().toString());
      }

      }

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

      Attachments

        Issue Links

          Activity

            People

              darcy Joe Darcy
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: