Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Divide BigDecimal by Integer  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()))
 
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Ravi Kanth D
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ....
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!