aspose file tools*
The moose likes JSP and the fly likes Dividing BigDecimals in Java or in JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Dividing BigDecimals in Java or in JSTL" Watch "Dividing BigDecimals in Java or in JSTL" New topic
Author

Dividing BigDecimals in Java or in JSTL

caleb momanyi
Ranch Hand

Joined: Jun 17, 2012
Posts: 43

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
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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

Joined: Jan 15, 2011
Posts: 72

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.


Thanks & Regards
Gopakumar
 
 
subject: Dividing BigDecimals in Java or in JSTL