Skip to content

Commit 8e0588f

Browse files
hansonrhansonr
authored andcommitted
BigDecimal tests
1 parent dc5d7b7 commit 8e0588f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

sources/net.sf.j2s.java.core/src/test/Test_BigDec.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ public static void main(String[] args) {
1717
testBDMul();
1818
testBDDiv();
1919

20+
System.out.println("testBD OK");
2021

2122
}
2223

23-
// failing testBDMul();
24+
// failing testBDDiv();
2425

2526

2627

@@ -67,10 +68,23 @@ private static void testBDMul() {
6768
}
6869

6970
private static void testBDDiv() {
70-
BigDecimal g;
71-
g = BigDecimal.valueOf(5).divide(BigDecimal.valueOf(2));
71+
BigDecimal g, a, b;
72+
a = new BigDecimal(0);
73+
b = new BigDecimal(2.01);
74+
g = a.divide(b,10,BigDecimal.ROUND_DOWN);
75+
System.out.println(g);
76+
a = new BigDecimal(5.1);
77+
b = new BigDecimal(2.01);
78+
g = a.divide(b,10,BigDecimal.ROUND_DOWN);
7279
System.out.println(g);
73-
assert(g.toString().equals("2.5"));
80+
assert(g.toString().equals("2.5373134328"));
81+
String zeros = "";
82+
for (int i = 0; i < 10; i ++) {
83+
g = new BigDecimal("50" + zeros).divide(BigDecimal.valueOf(2), 10, BigDecimal.ROUND_DOWN);
84+
System.out.println(g);
85+
assert(g.toString().equals("25" + zeros + ".0000000000"));
86+
zeros += "0";
87+
}
7488
System.out.println("testBDDiv OK");
7589
}
7690

0 commit comments

Comments
 (0)