wood burning stoves 2.0*
The moose likes Java in General and the fly likes Divide BigDecimal by Integer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Divide BigDecimal by Integer " Watch "Divide BigDecimal by Integer " New topic
Author

Divide BigDecimal by Integer

Ravi Kanth D
Greenhorn

Joined: Sep 14, 2003
Posts: 18
I am trying to do a calculation within a Jasper report (java based open source reporting tool).
I have a BigDecimal variable that I need to divide by Integer variable, below is my code, please let me know what is wrong.
varBigDecimal1.divide(BigDecimal.valueOf(varInteger1.doubleValue()))
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

Why don't you tell us - whats happening that you think is wrong. Looks OK to me! (BigDecimal is immutable so you need to assign the result to another variable though)


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Ravi Kanth D
Greenhorn

Joined: Sep 14, 2003
Posts: 18
My bad..the syntax was ok, its just that the divisor value at runtime was zero. The error message was saying "unable to parse expression.." that made me think something wrong with the variable assignment. Thanks.
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7807
    
  21

Ravi Kanth D wrote:I have a BigDecimal variable that I need to divide by Integer variable, below is my code, please let me know what is wrong.
varBigDecimal1.divide(BigDecimal.valueOf(varInteger1.doubleValue()))

There's nothing intrinsically wrong with it, but the redundant double conversion will slow things down.

varBigDecimal1.divide(BigDecimal.valueOf(varInteger1))

will work just as well.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Saifuddin Merchant
Ranch Hand

Joined: Feb 08, 2009
Posts: 605

Winston Gutkowski wrote:
There's nothing intrinsically wrong with it, but the redundant double conversion will slow things down.

varBigDecimal1.divide(BigDecimal.valueOf(varInteger1))will work just as well.

Winston


More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason...including blind stupidity.



Nothing wrong with the advice (it's probably sound) but yet whenever I see someone take about efficiency I love to use that quote ....
 
jQuery in Action, 2nd edition
 
subject: Divide BigDecimal by Integer