• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dividing BigDecimals in Java or in JSTL

 
caleb momanyi
Ranch Hand
Posts: 43
Firefox Browser Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello guys can somebody please help me understand why dividing two BigDecimals in JSTL throws


i have checked both values and i know they are both not equal to zero.

The only thing holding me back from throwing the computer out the window is the fact that i have solved the same problem before and it had something to do with setting round_mode but i can't remember how i did it.

in my jsp this is what i have


i am sure both totalA and totalB are not null or zero
 
Paul Clapham
Sheriff
Pie
Posts: 20971
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can see from the stack trace that BigDecimal.divide is being executed. And you can read for yourself in the API documentation that an exception (division by zero) will be thrown when the denominator of the division is zero. So I suggest that the denominator of the division was zero and you have made an error when you determined it was not zero.
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
caleb momanyi wrote:
i am sure both totalA and totalB are not null or zero


As per my knowledge, The Operator '/' in EL will not produce any Exception even though the denominator is '0'.. it produces 'infinity' as the result.
I tried to use opertaor '/' between two BigDecimal numbers in Java and got compilation Error :

operator / cannot be applied to java.math.BigDecimal,java.math.BigDecimal
System.out.println("Result : "+(b1 / b2));
^
1 error

Please provide your Code to make it more clear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic