rafa Posted January 15, 2007 Share Posted January 15, 2007 Hi all, I want to divide 2 BigDecimal variables ( $V{1} and $V{2} ). To make this, I´ve created a new BigDecimal variable called $V{total}, and I want that $V{total} = $V{1} / $V{2} Then, in the variable expression box of the variable called $V{total}, I´ve written:$V{1}.divide($V{2}) Is it that correct? The report compiles, but when it´s filling the report, I get an error: Error filling print... java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(Unknown Source) What is wrong?? Thanks in advance Post edited by: rafa, at: 2007/01/15 10:22Post edited by: rafa, at: 2007/01/15 12:37 Link to comment Share on other sites More sharing options...
rafa Posted January 15, 2007 Author Share Posted January 15, 2007 I´ve tried using the operators "add", "subtract" and "multiply" and it runs fine. So the problem is only with the "divide" operator. I suppose the problem it´s decimals or not integers results, but, what can I do? ThanksPost edited by: rafa, at: 2007/01/15 12:36 Link to comment Share on other sites More sharing options...
jmurray Posted January 16, 2007 Share Posted January 16, 2007 Google is your friend. $V{v1}.divide($V{v2}, new MathContext(100)) If your division results in a non-terminating decimal then an exception is thrown. So you scale simply it to something reasonable and exception be gone. Link to comment Share on other sites More sharing options...
rafa Posted January 16, 2007 Author Share Posted January 16, 2007 Thank you very much jmurray. I promise you that I look for the solution in Google, but I didn´t find it ;-) Thanks again and see you Rafa Link to comment Share on other sites More sharing options...
schaibaa Posted January 16, 2007 Share Posted January 16, 2007 There are several other ways to do it, too. Checkout the Sun BigDecimal javadocs - basically if it doesn't end in a whole number, you have to specify rounding behavior. Link to comment Share on other sites More sharing options...
roque Posted August 1, 2007 Share Posted August 1, 2007 I have never seen what your you say $V{a}.divide$V{b}â€. If what you want it is to divide two variables. So that nonbeams this new Double( $V{a}.doubleValue() / $V{b}.doubleValue() ) schaibaa wrote:There are several other ways to do it, too. Checkout the Sun BigDecimal javadocs - basically if it doesn't end in a whole number, you have to specify rounding behavior. Link to comment Share on other sites More sharing options...
srinu.ydlp Posted July 30, 2014 Share Posted July 30, 2014 I am also getting same problem even I give mathcontext i am getting this problem. Can anybody tell me the solution for this. Link to comment Share on other sites More sharing options...
kongzaohui123 Posted November 6, 2017 Share Posted November 6, 2017 Thank you very much jmurray. I love you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now