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 ----------
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 ----------
- duplicates
-
JDK-6480539 BigDecimal.stripTrailingZeros() has no effect on zero itself ("0.0")
- Closed