# Dividing BigDecimals in Java or in JSTL

posted 4 years ago

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

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

posted 4 years ago

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.

posted 4 years ago

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.

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