• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dividing BigDecimals in Java or in JSTL

 
Ranch Hand
Posts: 43
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 72
Hibernate Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic