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 - ###@###.###
======================================================================
- duplicates
-
JDK-4027509 java.math.BigDecimal constructor works wrong with negative numbers.
-
- Closed
-