java - "Non-terminating decimal expansion; no exact representable decimal result" happens even when divide by 100 -
this question has answer here:
my java code running on hp-ux hpdev b.11.23 u ia64 , produce following exception: java.lang.arithmeticexception: non-terminating decimal expansion; no exact representable decimal result.
the code causes it:
bigdecimal p_change = (bigdecimal)record.get("p_chng"); p_change.divide(new bigdecimal(100));
record simple collection of column values sql query.p_change comes table in oracle database column number(10,2).
i understand why happens.the frequency random, divide fine same data sometimes. wondering if has hardware.
could system.out on value p_change?
bigdecimal p_change = new bigdecimal(math.pi); system.out.println(p_change.divide(new bigdecimal(100))); // yields 0.03141592653589793115997963468544185161590576171875
it's identical code, substitution of p_change pi
the issue has deal not entering rounding mode. try using
p_change.divide(new bigdecimal(100), bigdecimal.round_half_up);
Comments
Post a Comment