Jump to content
We've recently updated our Privacy Statement, available here ×

Math with BigDecimal variables


rafa

Recommended Posts

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:22

Post edited by: rafa, at: 2007/01/15 12:37

Link to comment
Share on other sites

  • Replies 7
  • Created
  • Last Reply

Top Posters In This Topic

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?

 

Thanks

Post edited by: rafa, at: 2007/01/15 12:36

Link to comment
Share on other sites

  • 6 months later...

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

  • 6 years later...
  • 3 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...